From c2fcab67381247596b80de47631f9539fca910a5 Mon Sep 17 00:00:00 2001 From: matt Date: Fri, 26 Aug 2022 18:19:58 +0000 Subject: [PATCH] Add reload command --- commands/reload.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 commands/reload.js diff --git a/commands/reload.js b/commands/reload.js new file mode 100644 index 0000000..ddae032 --- /dev/null +++ b/commands/reload.js @@ -0,0 +1,38 @@ +'use strict'; + +const path = require('path'); + +const { SlashCommandBuilder } = require('discord.js'); + +const getCommands = require(path.join(__dirname, '../lib', 'getCommands.js')); +const unregisterCommands = require(path.join(__dirname, '..', 'unregisterCommands.js')); +const registerCommands = require(path.join(__dirname, '..', 'registerCommands.js')); + +const data = new SlashCommandBuilder() + .setName('reload') + .setDescription('Reload all commands to the latest version') + .addBooleanOption(option => + option.setName('full') + .setDescription('Fully re-register the commands with discord?') + ); + +const execute = async (interaction) => { + await interaction.reply('Fetching commands...'); + + interaction.client.commands = getCommands(); + + if (interaction.options.getBoolean('full')) { + await interaction.editReply('Unregistering commands...'); + await unregisterCommands(); + + await interaction.editReply('Registering new commands...'); + await registerCommands(); + } + + await interaction.editReply('Successfully reloaded commands!'); +}; + +module.exports = { + data, + execute +};