I made a reload command for a Discord bot and I want to be able to reload commands that are a new command instead of pre existing commands

  discord.js, javascript, node.js, raspberry-pi

So I made a reload command that reloads pre existing commands without pulling the bot offline. But now I want to be able to do an update with new commands I have added. Here is my code I have now

module.exports = {
    name: 'reload',
    aliasses: ['restart', 'rl'],
    cooldown: 0,
    usage: `reload <category> <command>`,
    description: 'Reloads a command',
    async execute(client, message, args, Discord, user, text){
        if(message.author.id !== `222855824928669696`) return message.channel.send('You are not a Dev');     
        if(!args[0]) return message.channel.send('You need to include the name of the command!');

        let command = args[0].toLowerCase();
        try {
            delete require.cache[require.resolve(`../commands/${command}.js`)]
            client.commands.delete(command);
            const pull = require(`../commands/${command}.js`);
            client.commands.set(command, pull);

            return message.channel.send(`**${command}** was reloaded succesfully!`);
        } catch (error) {
            return message.channel.send(`There was an error trying to reload **${command}**: `${error.message}``);
        }
    }
} 

In the end i want to reload pre existing commands and load new commands without taking the bot offline.

Source: Ask Javascript Questions

LEAVE A COMMENT