From a214f8530856110a280d284dcd9054593881601f Mon Sep 17 00:00:00 2001 From: AxleTiger Date: Tue, 31 Jan 2023 21:27:53 -0500 Subject: [PATCH 1/2] Created reloadCommand.js (read description) ##Added reloadCommand.js ##Notes Please lmk ducky if you want me to rework and add /bedwars and /skywars (ect) to the bot --- src/discord/commands/reloadCommand.js | 30 +++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/discord/commands/reloadCommand.js diff --git a/src/discord/commands/reloadCommand.js b/src/discord/commands/reloadCommand.js new file mode 100644 index 00000000..10d9a206 --- /dev/null +++ b/src/discord/commands/reloadCommand.js @@ -0,0 +1,30 @@ +const fs = require('fs'); +const path = require('path'); +const { REST } = require('@discordjs/rest') +const config = require('../../config.json') +const { Routes } = require('discord-api-types/v9') + + +module.exports = { + name: 'reload', + description: 'Reloads all the commands', + execute: async (interaction) => { + if ((await interaction.guild.members.fetch(interaction.user)).roles.cache.has(config.discord.commandRole)) { + const commands = [] + const _commandFiles = fs.readdirSync(path.join(__dirname,)).filter(file => file.endsWith('.js')); + + for (const file of _commandFiles) { + delete require.cache[require.resolve(`./${file}`)]; + const command = require(`./${file}`); + commands.push(command) + } + const rest = new REST({ version: '10' }).setToken(config.discord.token) + rest.put(Routes.applicationGuildCommands(config.discord.clientID, config.discord.serverID), { body: commands }).catch(console.error); + interaction.reply({ content: 'All commands have been reloaded!', ephemeral: true }); + console.log('All commands have been reloaded!') + + } else { + interaction.reply({ content: `You do not have permission to run this command!`, ephemeral: true}) + } + } +}; \ No newline at end of file From 6967916a4730a9b54e8a24b46d766b636ef81042 Mon Sep 17 00:00:00 2001 From: AxleTiger Date: Tue, 31 Jan 2023 22:09:40 -0500 Subject: [PATCH 2/2] so I broke it but I fixed it. --- src/discord/commands/reloadCommand.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/discord/commands/reloadCommand.js b/src/discord/commands/reloadCommand.js index 10d9a206..5375fb02 100644 --- a/src/discord/commands/reloadCommand.js +++ b/src/discord/commands/reloadCommand.js @@ -8,14 +8,19 @@ const { Routes } = require('discord-api-types/v9') module.exports = { name: 'reload', description: 'Reloads all the commands', - execute: async (interaction) => { + execute: async(interaction, message, args, client) => { if ((await interaction.guild.members.fetch(interaction.user)).roles.cache.has(config.discord.commandRole)) { const commands = [] const _commandFiles = fs.readdirSync(path.join(__dirname,)).filter(file => file.endsWith('.js')); for (const file of _commandFiles) { delete require.cache[require.resolve(`./${file}`)]; - const command = require(`./${file}`); + delete require.cache[require.resolve(`../../../src/discord/commands/${file}`)]; + delete require.cache[require.resolve(`../../../src/discord/commands/${file}`)]; + delete require.cache[require.resolve(`../../../src/discord/commands/${file}`)]; + delete require.cache[require.resolve(`../../../src/discord/commands/${file}`)]; + const command = require(`../../../src/discord/commands/${file}`); + client.commands.set(command.name, command); commands.push(command) } const rest = new REST({ version: '10' }).setToken(config.discord.token)