Add command to reload commands
This commit is contained in:
		
							parent
							
								
									5ca044b735
								
							
						
					
					
						commit
						2c44a552d6
					
				
							
								
								
									
										31
									
								
								commands/testing/reload.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								commands/testing/reload.js
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,31 @@
 | 
			
		||||
const { SlashCommandBuilder } = require('discord.js');
 | 
			
		||||
 | 
			
		||||
module.exports = {
 | 
			
		||||
    data: new SlashCommandBuilder()
 | 
			
		||||
    .setName('reload')
 | 
			
		||||
    .setDescription('Reload a command.')
 | 
			
		||||
    .addStringOption(option =>
 | 
			
		||||
        option.setName('command')
 | 
			
		||||
            .setDescription('The command to reload.')
 | 
			
		||||
            .setRequired(true)),
 | 
			
		||||
    async execute(interaction) {
 | 
			
		||||
        const commandName = interaction.options.getString('command', true).toLowerCase();
 | 
			
		||||
        const command = interaction.client.commands.get(commandName);
 | 
			
		||||
 | 
			
		||||
        if (!command) {
 | 
			
		||||
            return interaction.reply(`There is no command with name \`${commandName}\`!`);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        delete require.cache[require.resolve(`./${command.data.name}.js`)];
 | 
			
		||||
 | 
			
		||||
        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}\``);
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
};
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user