Holana/slash/reroll.js
2023-04-29 21:59:08 +12:00

62 lines
No EOL
2.1 KiB
JavaScript

const { ApplicationCommandOptionType } = require('discord.js');
module.exports = {
name: "reroll",
description: '🎉 Reroll a giveaway',
options: [
{
name: 'giveaway',
description: 'The giveaway to reroll (message ID)',
type: ApplicationCommandOptionType.String,
required: true
}
],
run: async (client, interaction) => {
// If the member doesn't have enough permissions
if (!interaction.member.permissions.has('MANAGE_MESSAGES') && !interaction.member.roles.cache.some((r) => r.name === "Giveaways")) {
return interaction.reply({
content: '<:x_:1010816180719722566> You need to have the manage messages permission to reroll giveaways.',
ephemeral: true
});
}
const query = interaction.options.getString('giveaway');
// try to find the giveaway with the provided prize OR with the ID
const giveaway =
// Search with giveaway ID
client.giveawaysManager.giveaways.find((g) => g.messageId === query && g.guildId === interaction.guild.id);
// If no giveaway was found
if (!giveaway) {
return interaction.reply({
content: 'Unable to find a giveaway for `' + query + '`.',
ephemeral: true
});
}
if (!giveaway.ended) {
return interaction.reply({
content: `[This Giveaway](https://discord.com/channels/${giveaway.guildId}/${giveaway.channelId}/${giveaway.messageId}) has not been ended yet`,
ephemeral: true
});
}
// Reroll the giveaway
client.giveawaysManager.reroll(giveaway.messageId)
.then(() => {
// Success message
interaction.reply(`Rerolled **[this giveaway](https://discord.com/channels/${giveaway.guildId}/${giveaway.channelId}/${giveaway.messageId})!**`);
})
.catch((e) => {
interaction.reply({
content: e,
ephemeral: true
});
});
}
};