RELOAD FINALLY WORKS WITH SLASHCMDS

This commit is contained in:
Sophie Marie 2022-11-09 18:57:29 -06:00
parent d9206fe7fa
commit 5af776f4c2

View file

@ -3,43 +3,42 @@ const { Constants } = require('discord.js');
module.exports = { module.exports = {
name: require('path').parse(__filename).name, name: require('path').parse(__filename).name,
description: 'Reloads a command', description: 'Reload a commands code',
options: [...Array(10).keys()].map(i => ({ options: [{
name: `option${i + 0}`, name: 'command',
description: 'Another option', description: 'The command you want to reload',
required: i === 0, required: true,
type: Constants.ApplicationCommandOptionTypes.STRING type: Constants.ApplicationCommandOptionTypes.STRING
})), }],
async parseInteraction (client, config, interaction) { async parseInteraction (client, config, interaction) {
await interaction.reply(this.handle(client, config, interaction.user, [...Array(10).keys()].map(i => interaction.options.getString(`option${i + 1}`)).filter(str => str))); await interaction.reply(this.handle(client, config, interaction.user, interaction.options.getString('command')));
}, },
handle (client, config, user, args) { handle (client, __, user, args) {
if (user.id === process.env.OWNERID) { if (user.id === process.env.OWNERID) {
if (!args.length) return client.generateErrorMessage('You forgot to provide anything to reload, you pillock', user.displayAvatarURL()); if (!args.length) return client.generateErrorMessage('You forgot to provide anything to reload, you pillock', user.displayAvatarURL());
let returnMessage = ''; let returnMessage = '';
args.forEach(async (arg) => { // args.forEach(async (arg) => {
const commandName = arg?.toLowerCase(); const commandName = args.toLowerCase();
const command = client.commands.get(commandName); const command = client.commands.get(commandName);
if (!command) { if (!command) {
returnMessage += `There is no command with name or alias \`${commandName}\`\n`; returnMessage += `There is no command with name or alias \`${commandName}\`\n`;
} else { } else {
delete require.cache[require.resolve(`./${command.name}.js`)]; delete require.cache[require.resolve(`./${command.name}.js`)];
try { try {
const newCommand = require(`./${command.name}.js`); const newCommand = require(`./${command.name}.js`);
client.commands.set(newCommand.name, newCommand); client.commands.set(newCommand.name, newCommand);
returnMessage += `Successfully reloaded \`${commandName}\`\n`; returnMessage += `Successfully reloaded \`${commandName}\`\n`;
console.log(`User reloaded ${command.name}.`); console.log(`User reloaded ${command.name}.`);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
returnMessage += `There was an error while reloading \`${command.name}\`\n`; returnMessage += `There was an error while reloading \`${command.name}\`\n`;
}
} }
}); }
return returnMessage; return returnMessage;
} else { } else {