From e44e0b23f3db26fe9cb8f62fdedc88f4f39e0102 Mon Sep 17 00:00:00 2001 From: Marius Begby Date: Tue, 29 Aug 2023 15:19:39 +0200 Subject: [PATCH] fix: fixed bug with not being able to read command data --- src/utils/deploySlashCommands.ts | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/utils/deploySlashCommands.ts b/src/utils/deploySlashCommands.ts index 4e4c839..e3de23a 100644 --- a/src/utils/deploySlashCommands.ts +++ b/src/utils/deploySlashCommands.ts @@ -20,22 +20,11 @@ const logger = loggerModule.child({ executionId: executionId }); +//TODO: Fix deploying not working with require() + const slashCommands: SlashCommandBuilder[] = []; const systemCommands: SlashCommandBuilder[] = []; -const commandFolders = fs.readdirSync(path.resolve('./dist/commands')); -for (const folder of commandFolders) { - const commandFiles = fs - .readdirSync(path.resolve(`./dist/commands/${folder}`)) - .filter((file) => file.endsWith('.js')); - - for (const file of commandFiles) { - /* eslint-disable @typescript-eslint/no-var-requires */ - const command = require(`../commands/${folder}/${file}`); - command.isSystemCommand - ? systemCommands.push(command.data.toJSON()) - : slashCommands.push(command.data.toJSON()); - } -} +const commandFolders = fs.readdirSync(path.resolve('./dist/interactions/commands')); if (!process.env.DISCORD_BOT_TOKEN) { throw new Error('DISCORD_BOT_TOKEN environment variable is not set.'); @@ -54,6 +43,20 @@ const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_BOT_TOKEN) ); } + for (const folder of commandFolders) { + const commandFiles = fs + .readdirSync(path.resolve(`./dist/interactions/commands/${folder}`)) + .filter((file) => file.endsWith('.js')); + + for (const file of commandFiles) { + const commandModule = await import(`../interactions/commands/${folder}/${file}`); + const command = commandModule.default; + command.isSystemCommand + ? systemCommands.push(command.data.toJSON()) + : slashCommands.push(command.data.toJSON()); + } + } + try { logger.debug(`Bot user slash commands found: ${slashCommands.map((command) => `/${command.name}`).join(', ')}`);