fix: add error handling to registering commands on startup

This commit is contained in:
Marius Begby committed 2023-07-19 21:43:26 +02:00
1 parent 72f3690bb3
commit e251299c0c
1 file changed
+12 -5
+12 -5
View File
@@ -5,16 +5,23 @@ const { Collection } = require('discord.js');
exports.registerClientCommands = (client) => {
logger.debug('Registering client commands...');
client.commands = new Collection();
const commandFolders = fs.readdirSync(path.resolve('./src/commands'));
for (const folder of commandFolders) {
const commandFiles = fs.readdirSync(path.resolve(`./src/commands/${folder}`)).filter((file) => file.endsWith('.js'));
const commandFiles = fs
.readdirSync(path.resolve(`./src/commands/${folder}`))
.filter((file) => file.endsWith('.js'));
for (const file of commandFiles) {
logger.debug(`Registering command ${folder}/${file}...`);
const command = require(`../commands/${folder}/${file}`);
client.commands.set(command.data.name, command);
try {
logger.debug(`Registering command ${folder}/${file}...`);
const command = require(`../commands/${folder}/${file}`);
client.commands.set(command.data.name, command);
} catch (error) {
logger.error(`Error registering command ${folder}/${file}: ${error.message}`);
throw error;
}
}
}
};