mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-04 14:38:49 +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) => {
|
exports.registerClientCommands = (client) => {
|
||||||
logger.debug('Registering client commands...');
|
logger.debug('Registering client commands...');
|
||||||
|
|
||||||
client.commands = new Collection();
|
client.commands = new Collection();
|
||||||
|
|
||||||
const commandFolders = fs.readdirSync(path.resolve('./src/commands'));
|
const commandFolders = fs.readdirSync(path.resolve('./src/commands'));
|
||||||
for (const folder of commandFolders) {
|
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) {
|
for (const file of commandFiles) {
|
||||||
logger.debug(`Registering command ${folder}/${file}...`);
|
try {
|
||||||
const command = require(`../commands/${folder}/${file}`);
|
logger.debug(`Registering command ${folder}/${file}...`);
|
||||||
client.commands.set(command.data.name, command);
|
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