From 1ffd9285457678ecf6dfce57d9b5d4dfc72ffdcc Mon Sep 17 00:00:00 2001 From: Sepp J Morris Date: Mon, 12 Oct 2020 14:42:39 +0200 Subject: [PATCH] Reload command example. - Update reload.js and zoizbot.njsproj --- zoizbot/commands/reload.js | 20 ++++++++++++++++++++ zoizbot/zoizbot.njsproj | 3 +++ 2 files changed, 23 insertions(+) create mode 100644 zoizbot/commands/reload.js diff --git a/zoizbot/commands/reload.js b/zoizbot/commands/reload.js new file mode 100644 index 0000000..e5b9c6e --- /dev/null +++ b/zoizbot/commands/reload.js @@ -0,0 +1,20 @@ +/* + * a command that reloads the command you have edited to memory + * so you dont have to reboot the bot + * good for testing, not so much for production + * ive added the permission test, to make sure not everybody spams reload + */ +exports.run = (zoizbot, message, args) => { + if (!message.member.hasPermission("ADMINISTRATOR")) + return message.reply("Sorry, you don't have permissions to use this!"); + if (!args || args.length < 1) return message.reply("Please provide the command name to reload."); + const commandName = args[0]; + if (!zoizbot.commands.has(commandName)) { + return message.reply("That command does not exist"); + } + delete require.cache[require.resolve(`./${commandName}.js`)]; + zoizbot.commands.delete(commandName); + const props = require(`./${commandName}.js`); + zoizbot.commands.set(commandName, props); + message.reply(`The command ${commandName} has been reloaded`); +}; \ No newline at end of file diff --git a/zoizbot/zoizbot.njsproj b/zoizbot/zoizbot.njsproj index 6c184bb..6de7af3 100644 --- a/zoizbot/zoizbot.njsproj +++ b/zoizbot/zoizbot.njsproj @@ -48,6 +48,9 @@ Code + + Code +