Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { RichEmbed } = require("discord.js");
- const { stripIndents } = require("common-tags");
- module.exports = {
- name: "giveaway",
- category: "fun",
- description: "Makes a new giveaway for an alloted time.",
- usage:
- "n.giveaway <time> [form of time] [quantity] [amount of winners possible] [gift]",
- run: async (client, message, args) => {
- if (message.deletable) message.delete();
- const errorEmbed = new RichEmbed();
- const successEmbed = new RichEmbed();
- let time = args[0];
- let formTime = args[1];
- let quantity = args[2];
- let amountWinners = args[3];
- let gift = args.splice(4, args.length).join(" ");
- let eventsRole = message.guild.roles.find("id", "665705887196774450");
- const giveawayChannel = message.guild.channels.find(
- channel => channel.id === `665714033982308377`
- );
- if (!message.member.roles.has(eventsRole.id)) {
- return message.channel
- .send(
- errorEmbed
- .setColor("#FFE9CE")
- .setDescription(
- `❌ **You do not have permission to use this command!**`
- )
- )
- .then(m => m.delete(5000));
- }
- if (!time) {
- return message.channel
- .send(
- errorEmbed
- .setColor("#FFE9CE")
- .setDescription(`❌ **You must specify a time for the giveaway!**`)
- )
- .then(m => m.delete(5000));
- }
- if (!formTime) {
- return message.channel
- .send(
- errorEmbed
- .setColor("#FFE9CE")
- .setDescription(
- `❌ **You must specify a form of time for the giveaway!**`
- )
- )
- .then(m => m.delete(5000));
- }
- if (!quantity) {
- return message.channel
- .send(
- errorEmbed
- .setColor("#FFE9CE")
- .setDescription(
- `❌ **You must specify how much you are giving away!**`
- )
- )
- .then(m => m.delete(5000));
- }
- if (!amountWinners) {
- return message.channel
- .send(
- errorEmbed
- .setColor("#FFE9CE")
- .setDescription(
- `❌ **You must specify how many winners you want for the giveaway!**`
- )
- )
- .then(m => m.delete(5000));
- }
- if (!gift) {
- return message.channel
- .send(
- errorEmbed
- .setColor("#FFE9CE")
- .setDescription(`❌ **You must specify what you are giving away!**`)
- )
- .then(m => m.delete(5000));
- }
- if (formTime === "second") {
- let newTime = Date.now() + parseInt(time) * 1000;
- } else if (formTime === "minute") {
- let newTime = Date.now() + parseInt(time) * 1000 * 60;
- } else if (formTime === "hour") {
- let newTime = Date.now() + parseInt(time) * 1000 * 60 * 60;
- } else if (formTime === "day") {
- let newTime = Date.now() + parseInt(time) * 1000 * 60 * 60 * 24;
- } else {
- return message.channel
- .send(
- errorEmbed
- .setColor("#FFE9CE")
- .setDescription(
- `❌ **You must specify a valid form of time for the giveaway!**`
- )
- )
- .then(m => m.delete(5000));
- }
- message.channel.send(
- successEmbed
- .setColor("#FFE9CE")
- .setTimestamp()
- .setDescription(`✅ **Successfully created giveaway!**`)
- );
- const giveawayEmbed = new RichEmbed()
- .setTitle(`Giveaway`)
- .setColor("#FFE9CE")
- .setTimestamp()
- .setFooter(`You must react to enter!`)
- .addField(
- `**${gift}** (x${quantity})`,
- stripIndents`**Host:** ${message.author}
- **Time of Giveaway:** ${time} ${formTime}(s)`
- );
- let azukiFiesty = await client.emojis.find(
- emoji => emoji.name === "azukifiesty"
- );
- var sendGiveaway = await giveawayChannel.send(giveawayEmbed);
- sendGiveaway.react(azukiFiesty);
- if (Date.now() > time) {
- var random = 0;
- var winners = [];
- var inList = false;
- var participants = sendGiveaway.reactions
- .get(azukiFiesty.id)
- .users.fetch();
- for (var i = 0; i < participants.length; i++) {
- if (participants[i].id == client.user.id) {
- participants.splice(i, 1);
- continue;
- }
- }
- if (participants.length == 0) {
- const noWinnersEmbed = new RichEmbed()
- .setTitle("No Winners")
- .setTimestamp()
- .setColor("#FFE9CE")
- .setDescription(
- `**There were no participants, so no one won the giveaway.** ˃̣̣̥⌓˂̣̣̥`
- );
- return giveawayChannel.send(noWinnersEmbed);
- }
- if (participants.length < amountWinners) {
- const noWinnersEmbed = new RichEmbed()
- .setTitle("No Winners")
- .setTimestamp()
- .setColor("#FFE9CE")
- .setDescription(
- `**There were not enough participants, so no one won the giveaway.** ˃̣̣̥⌓˂̣̣̥`
- );
- return giveawayChannel.send(noWinnersEmbed);
- }
- for (var i = 0; i < amountWinners; i++) {
- inList = false;
- random = Math.floor(Math.random() * participants.length);
- for (var y = 0; y < winners.length; y++) {
- if (winners[y] == participants[random]) {
- i--;
- inList = true;
- break;
- }
- }
- if (!inList) {
- winners.push(participants[random]);
- }
- if (Date.now() > time) {
- const logEmbed = new RichEmbed()
- .setColor("#FFE9CE")
- .setTimestamp()
- .setFooter(
- `To claim your prize, you must DM the host of this giveaway!`
- )
- .setTitle("Winner")
- .setDescription(`**Congratulations! You have won ${gift}!**`);
- giveawayChannel.send(winners, logEmbed);
- }
- }
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement