From 03ce8215271f8171db760c9f8a2e015487b8da9f Mon Sep 17 00:00:00 2001 From: Emily J Date: Sun, 18 Oct 2020 13:51:29 +1100 Subject: [PATCH] reload command --- bot/commands/Developer/reload.js | 38 ++++++++++++++++++++++++++++++++ bot/util/handlers.js | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 bot/commands/Developer/reload.js diff --git a/bot/commands/Developer/reload.js b/bot/commands/Developer/reload.js new file mode 100644 index 0000000..b00c72e --- /dev/null +++ b/bot/commands/Developer/reload.js @@ -0,0 +1,38 @@ +const Command = require('../../base/Command.js'); + +class Reload extends Command { + constructor (client) { + super(client, { + description: 'Latency and API response times.', + usage: '`reload [command]` - Reloads the specified command.', + examples: '`reload ping`', + devOnly: true + }); + } + + async run (message, args, data) { // eslint-disable-line no-unused-vars + if (!args[0]) return message.channel.send('You didnt tell me what command to reload!'); + + let command; + + if (this.client.commands.has(args[0])) { + command = this.client.commands.get(args[0]); + } else if (this.client.aliases.has(args[0])) { + command = this.client.commands.get(this.client.aliases.get(args[0])); + } + + if (!command) return message.channel.send( + `\`${args[0]}\` does not exist as a command or an alias.` + ); + + let res = await this.client.commandHandler.unload(command.help.name, command.help.category); + if (res) return message.channel.send('Error unloading: '+ res); + + res = await this.client.commandHandler.load(command.help.name, command.help.category); + if (res) return message.channel.send('Error loading: ' + res); + + return message.channel.send(`Reloaded \`${args[0]}\``); + } +} + +module.exports = Reload; diff --git a/bot/util/handlers.js b/bot/util/handlers.js index d80d04a..4476e07 100644 --- a/bot/util/handlers.js +++ b/bot/util/handlers.js @@ -79,7 +79,7 @@ class CommandHandler { commandFiles.filter((cmd) => cmd.split('.').pop() === 'js').forEach((cmd) => { cmd = cmd.substring(0, cmd.length - 3); const res = this.unload(cmd, dir); - if (res) this.client.logger.error(res); + if (res) this.client.logger.error('Command unload: ' + res); }); }); }