2022-12-02 08:54:36 +00:00
|
|
|
const Discord = require("discord.js");
|
|
|
|
const ms = require("ms");
|
2021-10-08 23:58:57 +00:00
|
|
|
const messages = require("../utils/messages");
|
|
|
|
|
|
|
|
module.exports = {
|
2022-12-02 08:54:36 +00:00
|
|
|
description: "Start a giveaway",
|
2021-10-08 23:58:57 +00:00
|
|
|
|
2022-12-02 08:54:36 +00:00
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: "duration",
|
|
|
|
description:
|
|
|
|
"How long the giveaway should last for. Example values: 1m, 1h, 1d",
|
|
|
|
type: Discord.ApplicationCommandOptionType.String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "winners",
|
|
|
|
description: "How many winners the giveaway should have",
|
|
|
|
type: Discord.ApplicationCommandOptionType.Integer,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "prize",
|
|
|
|
description: "What the prize of the giveaway should be",
|
|
|
|
type: Discord.ApplicationCommandOptionType.String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "channel",
|
|
|
|
description: "The channel to start the giveaway in",
|
|
|
|
type: Discord.ApplicationCommandOptionType.Channel,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
],
|
2021-10-08 23:58:57 +00:00
|
|
|
|
2022-12-02 08:54:36 +00:00
|
|
|
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 start giveaways.",
|
|
|
|
ephemeral: true,
|
|
|
|
});
|
|
|
|
}
|
2021-10-08 23:58:57 +00:00
|
|
|
|
2022-12-02 08:54:36 +00:00
|
|
|
const giveawayChannel = interaction.options.getChannel("channel");
|
|
|
|
const giveawayDuration = interaction.options.getString("duration");
|
|
|
|
const giveawayWinnerCount = interaction.options.getInteger("winners");
|
|
|
|
const giveawayPrize = interaction.options.getString("prize");
|
2021-10-08 23:58:57 +00:00
|
|
|
|
2022-12-02 08:54:36 +00:00
|
|
|
if (!giveawayChannel.isTextBased()) {
|
|
|
|
return interaction.reply({
|
|
|
|
content: ":x: Selected channel is not text-based.",
|
|
|
|
ephemeral: true,
|
|
|
|
});
|
|
|
|
}
|
2021-10-08 23:58:57 +00:00
|
|
|
|
2022-12-02 08:54:36 +00:00
|
|
|
// Start the giveaway
|
|
|
|
client.giveawaysManager.start(giveawayChannel, {
|
|
|
|
// The giveaway duration
|
|
|
|
duration: ms(giveawayDuration),
|
|
|
|
// The giveaway prize
|
|
|
|
prize: giveawayPrize,
|
|
|
|
// The giveaway winner count
|
|
|
|
winnerCount: giveawayWinnerCount,
|
|
|
|
// Who hosts this giveaway
|
|
|
|
hostedBy: client.config.hostedBy ? interaction.user : null,
|
|
|
|
// Messages
|
|
|
|
messages,
|
|
|
|
});
|
|
|
|
|
|
|
|
interaction.reply(`Giveaway started in ${giveawayChannel}!`);
|
|
|
|
},
|
2021-10-08 23:58:57 +00:00
|
|
|
};
|