Files
Femboy-Croissant-Bot/commands/dev/reload.js
2025-08-30 18:05:01 +02:00

39 lines
1.7 KiB
JavaScript

const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js');
module.exports = {
category: 'dev',
data: new SlashCommandBuilder()
.setName('reload')
.setDescription('Reloads a command.')
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)
.addStringOption(option =>
option.setName('command')
.setDescription('The command to reload.')
.setRequired(true)),
async execute(interaction) {
// Vérification côté bot pour être sûr
if (!interaction.member.permissions.has(PermissionFlagsBits.Administrator)) {
return interaction.reply({ content: '❌ Only administrators can use this command.', ephemeral: true });
}
const commandName = interaction.options.getString('command', true).toLowerCase();
const command = interaction.client.commands.get(commandName);
if (!command) {
return interaction.reply({ content: `There is no command with name \`${commandName}\`!`, ephemeral: true });
}
delete require.cache[require.resolve(`../${command.category}/${command.data.name}.js`)];
try {
const newCommand = require(`../${command.category}/${command.data.name}.js`);
interaction.client.commands.set(newCommand.data.name, newCommand);
await interaction.reply({ content: `✅ Command \`${newCommand.data.name}\` was reloaded!`, ephemeral: true });
} catch (error) {
console.error(error);
await interaction.reply({ content: `❌ Error while reloading \`${command.data.name}\`:\n\`${error.message}\``, ephemeral: true });
}
},
};