Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created reloadCommand.js (read description) #86

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/discord/commands/reloadCommand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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, 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}`)];
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)
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})
}
}
};