mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-03 06:28:53 +00:00
fix: add error handling to registering commands on startup
This commit is contained in:
1 parent
72f3690bb3
commit
e251299c0c
1 file changed
+12
-5
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user