Reputation: 39
I am on version 12 of discord.js, and I am making a giveaway command.
let embed = new Discord.MessageEmbed()
.setTitle('Giveaway!')
.setAuthor('Hosted by ' + message.author.username, message.author.avatarURL())
.setDescription('The prize is **' + prize + '**!')
.setTimestamp(Date.now() + ms(args[1]))
.setColor("BLUE")
let m = await channel.send(embed)
m.react("🎉")
setTimeout(() => {
if (m.reactions.cache.get("🎉").count <= 1) {
message.channel.send(`Reactions: ${m.reactions.cache.get("🎉").count}`);
return err('Not enough people reacted!')
}
That is my code, and i get this error:
if (m.reactions.cache.get("🎉").count <= 1) {
^
TypeError: Cannot read property 'count' of undefined
at Timeout._onTimeout (C:\Users\abhir\Downloads\Tada!\index.js:38:48)
at listOnTimeout (internal/timers.js:549:17)
at processTimers (internal/timers.js:492:7)
Details:
OS: Windows Home 64 Bit Node.JS Version: 12 Discord.JS Version: 12.0.0
Upvotes: 1
Views: 585
Reputation: 1464
You should try to refetch the message on completion of the timeout :
let m = await channel.send(embed);
m.react("🎉");
setTimeout(() => {
const message = channel.messages.cache.get(m.id);
const reactions = message.reactions.cache.get("🎉");
if (!reactions) return message.channel.send('No reactions found.');
if (reactions.count <= 1) {
message.channel.send(`Reactions: ${reactions.count}`);
return err('Not enough people reacted!');
}
// Do your stuff
Hope this will fix your issue :)
Upvotes: 1