mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-04 14:38:49 +00:00
feat: Added reload command
This commit is contained in:
1 parent
7c43daeb9b
commit
2c5d5ec3a5
3 files changed
+52
-2
No files matched your search
@@ -10,6 +10,7 @@ const { createPlayer } = require('./utils/factory/createPlayer.js');
|
|||||||
const player = await createPlayer(client);
|
const player = await createPlayer(client);
|
||||||
|
|
||||||
client.on('allShardsReady', async () => {
|
client.on('allShardsReady', async () => {
|
||||||
|
client.registerClientCommands = registerClientCommands;
|
||||||
registerEventListeners(client, player);
|
registerEventListeners(client, player);
|
||||||
registerClientCommands(client);
|
registerClientCommands(client);
|
||||||
client.emit('ready', client);
|
client.emit('ready', client);
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
const logger = require('../../services/logger');
|
||||||
|
const { embedOptions } = require('../../config');
|
||||||
|
const { notValidGuildId } = require('../../utils/validation/systemCommandValidator');
|
||||||
|
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
isSystemCommand: true,
|
||||||
|
isNew: false,
|
||||||
|
isBeta: false,
|
||||||
|
data: new SlashCommandBuilder()
|
||||||
|
.setName('reload')
|
||||||
|
.setDescription('Reload the bot commands.')
|
||||||
|
.setDMPermission(false)
|
||||||
|
.setNSFW(false),
|
||||||
|
execute: async ({ interaction, client }) => {
|
||||||
|
if (await notValidGuildId(interaction)) {
|
||||||
|
logger.debug(`[Shard ${client.shard.ids[0]}] Not a valid guild id.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await client.shard
|
||||||
|
.broadcastEval((shardClient) => {
|
||||||
|
shardClient.registerClientCommands(shardClient);
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
logger.info(`[Shard ${client.shard.ids[0]}] Reloaded commands across all shards.`);
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error, `[Shard ${client.shard.ids[0]}] Failed to reload commands.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const commands = client.commands.map((command) => {
|
||||||
|
let params = command.data.options[0] ? `**\`${command.data.options[0].name}\`**` + ' ' : '';
|
||||||
|
return `- **\`/${command.data.name}\`** ${params}- ${command.data.description}`;
|
||||||
|
});
|
||||||
|
|
||||||
|
let embedDescription = `**${embedOptions.icons.bot} Reloaded commands**\n` + commands.join('\n');
|
||||||
|
|
||||||
|
return await interaction.editReply({
|
||||||
|
embeds: [new EmbedBuilder().setDescription(embedDescription).setColor(embedOptions.colors.success)]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -15,14 +15,19 @@ exports.registerClientCommands = (client) => {
|
|||||||
|
|
||||||
for (const file of commandFiles) {
|
for (const file of commandFiles) {
|
||||||
try {
|
try {
|
||||||
logger.debug(`[Shard ${client.shard.ids[0]}] Registering command ${folder}/${file}...`);
|
logger.trace(`[Shard ${client.shard.ids[0]}] Registering command ${folder}/${file}...`);
|
||||||
|
|
||||||
|
// delete command from require cache
|
||||||
|
delete require.cache[require.resolve(`../commands/${folder}/${file}`)];
|
||||||
|
|
||||||
|
// register command
|
||||||
const command = require(`../commands/${folder}/${file}`);
|
const command = require(`../commands/${folder}/${file}`);
|
||||||
|
client.commands.delete(command.data.name);
|
||||||
client.commands.set(command.data.name, command);
|
client.commands.set(command.data.name, command);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(
|
logger.error(
|
||||||
`[Shard ${client.shard.ids[0]}] Error registering command ${folder}/${file}: ${error.message}`
|
`[Shard ${client.shard.ids[0]}] Error registering command ${folder}/${file}: ${error.message}`
|
||||||
);
|
);
|
||||||
throw error;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user