Holana/commands/end.js

65 lines
2 KiB
JavaScript
Raw Normal View History

2023-03-19 02:46:57 -07:00
const ms = require('ms');
2021-10-08 16:58:57 -07:00
module.exports = {
2021-10-09 00:31:19 -07:00
2023-03-19 02:46:57 -07:00
description: 'End a giveaway',
2021-10-09 00:31:19 -07:00
2023-03-19 02:46:57 -07:00
options: [
{
name: 'giveaway',
description: 'The giveaway to end (message ID or giveaway prize)',
type: 'STRING',
required: true
}
],
2021-10-08 16:58:57 -07:00
2023-03-19 02:46:57 -07:00
run: async (client, interaction) => {
2021-10-08 16:58:57 -07:00
2023-03-19 02:46:57 -07: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")){
return interaction.reply({
content: ':x: You need to have the manage messages permissions to end giveaways.',
ephemeral: true
});
}
2021-10-09 00:31:19 -07:00
2023-03-19 02:46:57 -07:00
const query = interaction.options.getString('giveaway');
2021-10-08 16:58:57 -07:00
2023-03-19 02:46:57 -07: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 16:58:57 -07:00
2023-03-19 02:46:57 -07:00
if (giveaway.ended) {
return interaction.reply({
content: 'This giveaway is already ended.',
ephemeral: true
});
}
// Edit the giveaway
client.giveawaysManager.end(giveaway.messageId)
2021-10-08 16:58:57 -07:00
// Success message
2023-03-19 02:46:57 -07:00
.then(() => {
// Success message
interaction.reply('Giveaway ended!');
})
.catch((e) => {
interaction.reply({
content: e,
ephemeral: true
});
2021-10-08 16:58:57 -07:00
});
2023-03-19 02:46:57 -07:00
}
2021-10-08 16:58:57 -07:00
};