0
votes

so basically I have this giveaway command which works good but if u react with the emoji after the time u set is done it will just send "Not enough people reacted for me to draw a winner it won't pick the winner" Idk why this is happening.

client.on('message', async message =>{
  if(message.content.toLowerCase().startsWith(prefix + 'giveaway')) {
    if(!message.member.hasPermission("MANAGE_MESSAGES")) 
return message.channel.send('You cant use this command sice youre missing `manage_messages` perm')
    let args = message.content.substring(prefix.length).split(" ")
    let time = args[1]
    if(!time) return message.channel.send('You did not specify your time');
    if(
      !args[1].endsWith("d") &&
      !args[1].endsWith("h") &&
      !args[1].endsWith("m") &&
      !args[1].endsWith("s")
    )
    return message.channel.send("You need to use d (days), h (hours), m (minutes), or s (seconds)")

    let gchannel = message.mentions.channels.first();
    if(!gchannel) return message.channel.send("I cant find that channel in the server.")
    let prize = args.slice(3).join(" ")
    if(!prize) return message.channel.send('What is the prize?')

    message.delete()
    gchannel.send(`:tada: **New Giveaway** :tada:`)
    const newEmbed = new Discord.MessageEmbed()
    .setTitle('New Giveaway')
    .setColor("RANDOM")
    .setDescription(`React with :tada: to enter the giveaway. 
\nHosted By: **${message.author}** \nTime: **${time}**\nPrize: **${prize}**`)
    .setFooter(`Will end in ${time}`)
    let reaction = await gchannel.send(newEmbed)
    reaction.react("????")
    setTimeout(() => {
      if ((m) => m.reaction.cache.get("????").count <= 0) {
        return message.channel.send("Not enough people reacted for me to draw a winner")
      }
      let winner = (m) => m.reaction.cache.get("????").users.cache.filter((u) => !u.bot).random();
      gchannel.send(`Congratulations ${winner} You just won the **${prize}**!`
      );
    }, ms(args[1]));
  }
})
1
Where does m come from? You can't do that. You need to get the actual message object with the reactions on it (reaction) - Pentium1080Ti
how can i do that? - PoXoS
You already have it in the reaction variable - Pentium1080Ti
idk what to change or what to change it instead - PoXoS
Well .send() returns a promise that contains a Message object, which has the property reactions on it - Pentium1080Ti

1 Answers

0
votes

You can't use an arrow function for no reason on your if statement, as m has not been set to anything, you will get undefined.

To fix this, you need to use the message you send as your Message object, as when you use .send() a promise is returned, which contains a Message object. This object then has the property reactions which can be used to get the reactions on the message.

For example:

if (reaction.reactions.cache.get("🎉").count <= 0) {
    return message.channel.send("Not enough people reacted for me to draw a winner")
}

However, I would suggest using a ReactionCollector instead as you can setup a filter and a time and then an event will be fired off instead, which you can listen to and get the size of etc.

const filter = (reaction, user) => {
    return reaction.emoji.name === '🎉';
};

const collector = reaction.createReactionCollector(filter, { time: 15000 });
// time is in ms (so 15000ms is 15 seconds)

collector.on('collect', (reaction, user) => {
    console.log(`Collected 🎉 from ${user.tag}`);
});

collector.on('end', collected => {
    console.log(`Collected ${collected.size} items`);
    // collected.size will only contain the number of 🎉 on the message, as the collector had a filter applied to it
});