2021-10-08 23:58:57 +00:00
|
|
|
const ms = require('ms');
|
|
|
|
|
|
|
|
module.exports = {
|
2021-10-09 07:31:19 +00:00
|
|
|
|
|
|
|
description: 'End a giveaway',
|
|
|
|
|
2021-10-08 23:58:57 +00:00
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'giveaway',
|
2021-10-09 07:31:19 +00:00
|
|
|
description: 'The giveaway to end (message ID or giveaway prize)',
|
2021-10-08 23:58:57 +00:00
|
|
|
type: 'STRING',
|
|
|
|
required: true
|
|
|
|
}
|
|
|
|
],
|
|
|
|
|
|
|
|
run: async (client, interaction) => {
|
2021-10-09 07:31:19 +00:00
|
|
|
|
|
|
|
// If the member doesn't have enough permissions
|
|
|
|
if(!interaction.member.permissions.has('MANAGE_MESSAGES') && !interaction.member.roles.cache.some((r) => r.name === "Giveaways")){
|
2021-10-08 23:58:57 +00:00
|
|
|
return interaction.reply({
|
2021-10-09 07:31:19 +00:00
|
|
|
content: ':x: You need to have the manage messages permissions to end giveaways.',
|
2021-10-08 23:58:57 +00:00
|
|
|
ephemeral: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
const query = interaction.options.getString('giveaway');
|
|
|
|
|
2021-10-09 07:31:19 +00:00
|
|
|
// try to found the giveaway with prize then with ID
|
|
|
|
const giveaway =
|
|
|
|
// Search with giveaway prize
|
|
|
|
client.giveawaysManager.giveaways.find((g) => g.prize === query && g.guildId === interaction.guild.id) ||
|
|
|
|
// 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
|
|
|
|
});
|
|
|
|
}
|
2021-10-08 23:58:57 +00:00
|
|
|
|
2021-10-09 07:31:19 +00:00
|
|
|
if (giveaway.ended) {
|
2021-10-08 23:58:57 +00:00
|
|
|
return interaction.reply({
|
2021-10-09 07:31:19 +00:00
|
|
|
content: 'This giveaway is already ended.',
|
2021-10-08 23:58:57 +00:00
|
|
|
ephemeral: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Edit the giveaway
|
|
|
|
client.giveawaysManager.end(giveaway.messageId)
|
|
|
|
// Success message
|
|
|
|
.then(() => {
|
|
|
|
// Success message
|
2021-10-09 07:31:19 +00:00
|
|
|
interaction.reply('Giveaway ended!');
|
2021-10-08 23:58:57 +00:00
|
|
|
})
|
|
|
|
.catch((e) => {
|
|
|
|
interaction.reply({
|
|
|
|
content: e,
|
|
|
|
ephemeral: true
|
2021-10-09 07:31:19 +00:00
|
|
|
});
|
2021-10-08 23:58:57 +00:00
|
|
|
});
|
2021-10-09 07:31:19 +00:00
|
|
|
|
2021-10-08 23:58:57 +00:00
|
|
|
}
|
|
|
|
};
|