From 2f51c18a693cd6503c6e0e527da1f571a14bd1cd Mon Sep 17 00:00:00 2001 From: Bradley Bickford Date: Sun, 31 Dec 2023 09:39:25 -0500 Subject: [PATCH] Trying some upgrades to command loading --- breadbot.js | 28 ++++++++++++++++++++-------- commands/ping.js | 1 + commands/server.js | 1 + commands/user.js | 1 + 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/breadbot.js b/breadbot.js index c28d68a..c815a27 100644 --- a/breadbot.js +++ b/breadbot.js @@ -26,29 +26,41 @@ const getAllFiles = function(directoryPath, arrayOfFiles) { return arrayOfFiles; }; -const allFiles = []; -getAllFiles('.' + path.sep + 'commands', allFiles); - const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildVoiceStates] }); client.commands = new Collection(); -const commandFiles = allFiles.filter(file => file.endsWith('.js')); +//const commandFiles = allFiles.filter(file => file.endsWith('.js')); var activeCalls = [] +getAllFiles('.' + path.sep + 'commands', []) + .filter(file => file.endsWith('.js')) + .forEach(file => { + const command = require(file); + + if ('enabled' in command && command.enabled && 'data' in command && 'execute' in command) { + client.commands.set(command.data.name, command); + console.log(`[INFO] Loaded command at ${file}`); + } + else { + console.log(`[WARNING] The command at ${file} is missing a required "data" or "execute" property or is not enabled.`); + } + }); + +/* for (const file of commandFiles) { const command = require(file); - if ('data' in command && 'execute' in command) { + if ('enabled' in command && command.enabled && 'data' in command && 'execute' in command) { client.commands.set(command.data.name, command); console.log(`[INFO] Loaded command at ${file}`); } else { - console.log(`[WARNING] The command at ${file} is missing a required "data" or "execute" property.`); + console.log(`[WARNING] The command at ${file} is missing a required "data" or "execute" property or is not enabled.`); } } - +*/ client.on(Events.InteractionCreate, async interaction => { if (!interaction.isChatInputCommand()) return; @@ -305,7 +317,7 @@ client.on(Events.MessageDelete, async deletedMessage => { }) client.once(Events.ClientReady, c => { - console.log(`Ready! Logged in as ${c.user.tag}`); + console.log(`Ready! Logged in as ${c.user.tag} - ${c.user.id}`); }); client.login(token); \ No newline at end of file diff --git a/commands/ping.js b/commands/ping.js index d77b4b0..b47fe8f 100644 --- a/commands/ping.js +++ b/commands/ping.js @@ -1,6 +1,7 @@ const { SlashCommandBuilder } = require('discord.js'); module.exports = { + enabled: true, data: new SlashCommandBuilder() .setName('ping') .setDescription('Replies with Pong!'), diff --git a/commands/server.js b/commands/server.js index 5053708..6743027 100644 --- a/commands/server.js +++ b/commands/server.js @@ -1,6 +1,7 @@ const { SlashCommandBuilder } = require('discord.js'); module.exports = { + enabled: true, data: new SlashCommandBuilder() .setName('server') .setDescription('Provides information about the server.'), diff --git a/commands/user.js b/commands/user.js index 2b47b16..fbc3a8a 100644 --- a/commands/user.js +++ b/commands/user.js @@ -1,6 +1,7 @@ const { SlashCommandBuilder } = require('discord.js'); module.exports = { + enabled: true, data: new SlashCommandBuilder() .setName('user') .setDescription('Provides information about the user.'),