From a32079a4f0714927ac7bb32566e74bd2591f3488 Mon Sep 17 00:00:00 2001 From: rhearmas <34490428+qu-ota@users.noreply.github.com> Date: Fri, 20 Dec 2019 19:58:25 -0500 Subject: [PATCH] OH MY GOD I FINALLY FIXED THIS AFTER A MONTH OF ISSUES --- commands/Utility/reload.js | 52 +++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/commands/Utility/reload.js b/commands/Utility/reload.js index c1a89be..cff0928 100644 --- a/commands/Utility/reload.js +++ b/commands/Utility/reload.js @@ -1,25 +1,47 @@ exports.run = async (client, message, args, level) => { - if (!args || args.length < 1) return message.reply("why are you trying to reload a command without actually naming it?"); - const command = client.commands.get(args[0]) || client.commands.get(client.aliases.get(args[0])); - let response = await client.unloadCommand(args[0]); - if (response) return message.reply(`Error Unloading: ${response}`); + message.delete(); - response = client.loadCommand(`${command.help.name}`); - if (response) return message.reply(`Error Loading: ${response}`); + if (!args || args.length < 1) return msg.edit("Why are you trying to reload a command without actually naming it?").then(msg => { + msg.delete(5000); + }); + + const commandName = args[0].toLowerCase(); + const command = message.client.commands.get(commandName) + || message.client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName)); - message.reply(`command \`${command.help.name}\` has been reloaded successfully.`); + if (!command) return msg.edit(`There is no command with name or alias \`${commandName}\`, ${message.author}.`).then(msg => { + msg.delete(5000); + }); + let msg = await message.channel.send(`**Beginning reload process;** initiated by ${message.author.tag}. Finding and reloading command \`${args[0]}\`...`); + + delete require.cache[require.resolve(`../${command.help.category}/${commandName}.js`)]; + + try { + const newCommand = require(`../${command.help.category}/${commandName}.js`); + message.client.commands.set(newCommand.help.name, newCommand); + } catch (error) { + console.log(error); + msg.edit(`Hey ${message.author}, there was an error while reloading command \`${commandName}\`:\n\`${error.message}\``).then(msg => { + msg.delete(10000); + }); + } + + msg.edit(`**Command \`${command.help.name}\` has been reloaded successfully.**`).then(msg => { + msg.delete(5000); + }); }; + exports.conf = { - enabled: true, - guildOnly: false, - aliases: [], - permLevel: "Bot Admin" + enabled: true, + guildOnly: false, + aliases: [], + permLevel: "Bot Admin" }; exports.help = { - name: "reload", - category: "System", - description: "Reloads a command that\'s been modified.", - usage: "reload [command]" + name: "reload", + category: "System", + description: "Reloads a command that\'s been modified.", + usage: "reload [command]" }; \ No newline at end of file