fix: fixed bug with not being able to read command data

This commit is contained in:
Marius Begby committed 2023-08-29 15:19:39 +02:00
1 parent 67e45729a3
commit e44e0b23f3
1 file changed
+17 -14
+17 -14
View File
@@ -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(', ')}`);