mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-03 06:28:53 +00:00
72 lines
2.8 KiB
JavaScript
72 lines
2.8 KiB
JavaScript
const config = require('config');
|
|
const embedOptions = config.get('embedOptions');
|
|
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, executionId }) => {
|
|
const logger = require('../../services/logger').child({
|
|
source: 'reload.js',
|
|
module: 'slashCommand',
|
|
name: '/reload',
|
|
executionId: executionId,
|
|
shardId: interaction.guild.shardId,
|
|
guildId: interaction.guild.id
|
|
});
|
|
|
|
if (await notValidGuildId({ interaction, executionId })) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
logger.info('Reloading commands across all shards.');
|
|
logger.info(`Execution ID: ${executionId}`);
|
|
await client.shard
|
|
.broadcastEval(
|
|
async (shardClient, { executionId }) => {
|
|
shardClient.registerClientCommands({ client: shardClient, executionId });
|
|
},
|
|
{ context: { executionId: executionId } }
|
|
)
|
|
.then(() => {
|
|
logger.info('Successfully reloaded commands across all shards.');
|
|
});
|
|
} catch (error) {
|
|
logger.error(error, 'Failed to reload commands across shards.');
|
|
|
|
logger.debug('Responding with error embed.');
|
|
return await interaction.editReply({
|
|
embeds: [
|
|
new EmbedBuilder()
|
|
|
|
.setDescription(
|
|
`**${embedOptions.icons.error} Oops!**\n_Hmm.._ It seems I am unable to reload commands across shards.`
|
|
)
|
|
.setColor(embedOptions.colors.error)
|
|
.setFooter({ text: `Execution ID: ${executionId}` })
|
|
]
|
|
});
|
|
}
|
|
|
|
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');
|
|
|
|
logger.debug('Responding with success embed.');
|
|
return await interaction.editReply({
|
|
embeds: [new EmbedBuilder().setDescription(embedDescription).setColor(embedOptions.colors.success)]
|
|
});
|
|
}
|
|
};
|