Undo changes to reload

This commit is contained in:
IDeletedSystem64 2022-11-09 23:27:13 -06:00
parent 5af776f4c2
commit b817c6b997
1 changed files with 25 additions and 24 deletions

View File

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