2022-12-06 21:06:39 -06:00
|
|
|
const { ApplicationCommandOptionType } = require('discord.js');
|
2022-04-22 00:11:53 -05:00
|
|
|
|
2021-02-06 11:10:52 -06:00
|
|
|
module.exports = {
|
2022-04-18 11:25:40 -05:00
|
|
|
|
2022-04-21 18:09:21 -05:00
|
|
|
name: require('path').parse(__filename).name,
|
|
|
|
description: 'Reloads a command',
|
2022-04-22 00:11:53 -05:00
|
|
|
options: [...Array(10).keys()].map(i => ({
|
2022-08-02 23:53:10 -05:00
|
|
|
name: `option${i + 0}`,
|
2022-04-22 00:11:53 -05:00
|
|
|
description: 'Another option',
|
2022-04-22 15:16:14 -05:00
|
|
|
required: i === 0,
|
2022-12-06 21:06:39 -06:00
|
|
|
type: ApplicationCommandOptionType.User
|
2022-04-22 00:11:53 -05:00
|
|
|
})),
|
2022-04-18 11:25:40 -05:00
|
|
|
|
2022-04-21 23:44:02 -05:00
|
|
|
async parseMessage (client, config, message, args) {
|
2022-04-22 15:07:25 -05:00
|
|
|
await message.channel.send(this.handle(client, config, message.author, args));
|
2022-04-21 23:44:02 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
async parseInteraction (client, config, interaction) {
|
2022-04-22 00:22:02 -05:00
|
|
|
await interaction.reply(this.handle(client, config, interaction.user, [...Array(10).keys()].map(i => interaction.options.getString(`option${i + 1}`)).filter(str => str)));
|
2022-04-21 23:44:02 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
handle (client, config, user, args) {
|
2022-08-02 23:53:10 -05:00
|
|
|
if (user.id === process.env.OWNERID) {
|
2022-04-22 15:02:05 -05:00
|
|
|
if (!args.length) return client.generateErrorMessage('You forgot to provide anything to reload, you pillock', user.displayAvatarURL());
|
2022-04-21 23:44:02 -05:00
|
|
|
let returnMessage = '';
|
|
|
|
|
2022-03-26 12:31:03 -05:00
|
|
|
args.forEach(async (arg) => {
|
2022-04-22 00:22:02 -05:00
|
|
|
const commandName = arg?.toLowerCase();
|
2022-05-01 20:11:30 -05:00
|
|
|
const command = client.commands.get(commandName);
|
2021-02-06 11:10:52 -06:00
|
|
|
|
2022-03-26 12:31:03 -05:00
|
|
|
if (!command) {
|
2022-04-21 23:44:02 -05:00
|
|
|
returnMessage += `There is no command with name or alias \`${commandName}\`\n`;
|
2022-03-26 12:31:03 -05:00
|
|
|
} else {
|
|
|
|
delete require.cache[require.resolve(`./${command.name}.js`)];
|
2021-02-06 11:10:52 -06:00
|
|
|
|
2022-03-26 12:31:03 -05:00
|
|
|
try {
|
|
|
|
const newCommand = require(`./${command.name}.js`);
|
|
|
|
client.commands.set(newCommand.name, newCommand);
|
2022-04-21 23:44:02 -05:00
|
|
|
returnMessage += `Successfully reloaded \`${commandName}\`\n`;
|
2022-04-21 18:09:21 -05:00
|
|
|
console.log(`User reloaded ${command.name}.`);
|
2022-03-26 12:31:03 -05:00
|
|
|
} catch (error) {
|
|
|
|
console.error(error);
|
2022-04-21 23:44:02 -05:00
|
|
|
returnMessage += `There was an error while reloading \`${command.name}\`\n`;
|
2022-03-26 12:31:03 -05:00
|
|
|
}
|
2022-03-26 03:33:18 -05:00
|
|
|
}
|
2022-03-26 12:31:03 -05:00
|
|
|
});
|
2022-04-21 23:44:02 -05:00
|
|
|
|
|
|
|
return returnMessage;
|
2022-03-26 03:33:18 -05:00
|
|
|
} else {
|
2022-07-03 18:13:35 -05:00
|
|
|
console.error(`[SYSTEM] [ERR] User ${user.username} tried to reload ${args[0]}, but doesn't have permission!`);
|
|
|
|
return client.generateErrorMessage("You don't have permission to run this command.", user.displayAvatarURL());
|
2022-03-27 17:03:17 -05:00
|
|
|
}
|
|
|
|
}
|
2022-04-21 18:09:21 -05:00
|
|
|
};
|