0
votes

So I am making Discord bot for my server and it works pretty well so far, save for one issue which seems really small, but I can't find solution despite reading documentation.

Basically I send embed with reactions and it works fine, but if someone doesn't react within particular amount of time, bot creates another emoji reaction and here's the issue. I want it to collect the very first person who reacts to new emoji instead of message author. Here's this part of the code:

.catch(collected => {
    message.channel.sendMessage("You run out of time, maybe someone else wants it?");

    const filter = (reaction, user) => {
    return ['????'].includes(reaction.emoji.name) && user.id === message.author.id;
    };

    embedMessage.react('????');

    embedMessage.awaitReactions(filter, {
      max: 1,
      time: 45000,
      errors: ['time']
    }).then(collected => {

    const reaction = collected.first();

    if (reaction.emoji.name === '????'){
      message.channel.sendMessage("Yay.");

    }    
  });    
});

So I wonder if this is about this part:

return ['????'].includes(reaction.emoji.name) && user.id === message.author.id;

I tried replacing message.author.id with reaction.users, but it doesn't seem to work.

1

1 Answers

0
votes

Kian here,

This code should work for you, I've removed the check for user.id == message.author.id. If it doesn't work feel free to leave a comment and ill fix it.

.catch(collected => {
    message.channel.sendMessage("You run out of time, maybe someone else wants it?");

/*
 * I think that your error his here, you are trying to check if the user's id is the same
 * as the authors id, returning if it isnt, an easy way around this is to simply remove
 * "&& user.id === message.author.id".
 */

const filter = (reaction, user) => ['🉑'].includes(reaction.emoji.name);


// im going to leave everything under here alone
    embedMessage.react('🉑');

    embedMessage.awaitReactions(filter, {
      max: 1,
      time: 45000,
      errors: ['time']
    }).then(collected => {

    const reaction = collected.first();

    if (reaction.emoji.name === '🉑'){
      message.channel.sendMessage("Yay.");

    }    
  });    
});