2023-11-27 00:02:34 +01:00
|
|
|
const { SlashCommandBuilder } = require('discord.js');
|
2023-11-18 21:27:02 +01:00
|
|
|
|
2023-11-27 00:02:34 +01:00
|
|
|
module.exports = {
|
|
|
|
data: new SlashCommandBuilder()
|
|
|
|
.setName('reload')
|
|
|
|
.setDescription('Reload a command.')
|
|
|
|
.addStringOption(option =>
|
|
|
|
option.setName('command')
|
|
|
|
.setDescription('The command to reload.')
|
|
|
|
.setRequired(true)),
|
2023-11-18 21:27:02 +01:00
|
|
|
|
2023-11-27 00:02:34 +01:00
|
|
|
async execute(interaction) {
|
|
|
|
const commandName = interaction.options.getString('command', true).toLowerCase();
|
|
|
|
const command = interaction.client.commands.get(commandName);
|
2023-11-18 21:27:02 +01:00
|
|
|
|
2023-11-27 00:02:34 +01:00
|
|
|
if (!command) {
|
|
|
|
return interaction.reply(`There is no command with name \`${commandName}\`!`);
|
|
|
|
}
|
2023-11-18 21:27:02 +01:00
|
|
|
|
2023-11-27 00:02:34 +01:00
|
|
|
delete require.cache[require.resolve(`./${command.data.name}.js`)];
|
2023-11-20 00:59:41 +01:00
|
|
|
|
2023-11-27 00:02:34 +01:00
|
|
|
try {
|
|
|
|
interaction.client.commands.delete(command.data.name);
|
|
|
|
const newCommand = require(`./${command.data.name}.js`);
|
|
|
|
interaction.client.commands.set(newCommand.data.name, newCommand);
|
|
|
|
await interaction.reply(`Command \`${newCommand.data.name}\` was reloaded!`);
|
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
|
|
|
await interaction.reply(`There was an error while reloading a command \`${command.data.name}\`:\n\`${error.message}\``);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|