Holana/commands/pause.js

71 lines
1.9 KiB
JavaScript
Raw Permalink Normal View History

2023-11-26 09:26:08 +00:00
const Discord = require("discord.js");
module.exports = {
description: "Pause a giveaway",
options: [
{
name: "giveaway",
description: "The giveaway to pause (message ID or giveaway prize)",
type: Discord.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: You need to have the manage messages permissions to pause giveaways.",
ephemeral: true,
});
}
const query = interaction.options.getString("giveaway");
// 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,
});
}
if (giveaway.pauseOptions.isPaused) {
return interaction.reply({
content: "This giveaway is already paused.",
ephemeral: true,
});
}
// Edit the giveaway
client.giveawaysManager
.pause(giveaway.messageId)
// Success message
.then(() => {
// Success message
interaction.reply("Giveaway paused!");
})
.catch((e) => {
interaction.reply({
content: e,
ephemeral: true,
});
});
},
};