Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
29
rated 0 times [  35] [ 6]  / answers: 1 / hits: 6805  / 4 Years ago, fri, may 29, 2020, 12:00:00

I am trying to make a Discord.js giveaway command that send an embed, save it to the variable embedSent then collect the reactions after the TimeOut with the reactions.get() method, but I keep getting the error TypeError: embedSent.reactions.get is not a function Here is the part of my code :


var embed = new Discord.MessageEmbed();
embed.setColor(0x3333ff);
embed.setTitle("Nouveau Giveaway !");
embed.setDescription("**" + item + "**");
embed.addField(`Durรฉe : `, ms(ms(time), {
long: true
}), true);
embed.setFooter("Rรฉagissez ร  ce message avec ๐ŸŽ‰ pour participer !");
var embedSent = await message.channel.send(embed);
embedSent.react("๐ŸŽ‰");

setTimeout(function () {
var peopleReacted = embedSent.reactions.get("๐ŸŽ‰").users.filter(user => user.id !== client.user.id).array()
}, time);

More From » bots

 Answers
7

Ok, after almost 2 months, I finally figured it out. The full, working command (DiscordJS v12) :


if (command == "giveaway") {
// !giveaway {time s/m/d} {item}
const messageArray = message.content.split(" ");
if (!message.member.hasPermission(["ADMINISTRATOR"])) return message.channel.send("You don't have enough permissions to start a giveaway !")
var item = "";
var time;
var winnerCount;
for (var i = 1; i < args.length; i++) {
item += (args[i] + " ");
}
time = args[0];
if (!time) {
return message.channel.send(`Invalid duration provided`);
}
if (!item) {
item = "No title"
}
var embed = new Discord.MessageEmbed();
embed.setColor(0x3333ff);
embed.setTitle("New Giveaway !");
embed.setDescription("**" + item + "**");
embed.addField(`Duration : `, ms(ms(time), {
long: true
}), true);
embed.setFooter("React to this message with ๐ŸŽ‰ to participate !");
var embedSent = await message.channel.send(embed);
embedSent.react("๐ŸŽ‰");

setTimeout(async () => {
try{
const peopleReactedBot = await embedSent.reactions.cache.get("๐ŸŽ‰").users.fetch();
var peopleReacted = peopleReactedBot.array().filter(u => u.id !== client.user.id);
}catch(e){
return message.channel.send(`An unknown error happened during the draw of the giveaway **${item}** : `+"`"+e+"`")
}
var winner;

if (peopleReacted.length <= 0) {
return message.channel.send(`Not enough participants to execute the draw of the giveaway **${item}** :(`);
} else {
var index = Math.floor(Math.random() * peopleReacted.length);
winner = peopleReacted[index];
}
if (!winner) {
message.channel.send(`An unknown error happened during the draw of the giveaway **${item}**`);
} else {
console.log(`Giveaway ${item} won by ${winner.toString()}`)
message.channel.send(`๐ŸŽ‰ **${winner.toString()}** has won the giveaway **${item}** ! Congratulations ! ๐ŸŽ‰`);
}
}, ms(time));
}

Hope it helped some !


[#3651] Wednesday, May 27, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
alli

Total Points: 409
Total Questions: 101
Total Answers: 105

Location: The Bahamas
Member since Tue, Apr 27, 2021
3 Years ago
alli questions
Sat, Apr 23, 22, 00:00, 2 Years ago
Mon, May 18, 20, 00:00, 4 Years ago
Tue, Mar 24, 20, 00:00, 4 Years ago
Fri, Jan 24, 20, 00:00, 4 Years ago
;