user11287402
user11287402

Reputation:

Having trouble with await reactions

I want the bot to delete it's message after a user reacts to the message with a specific emoji. When I tried this with the code below, nothing happens. No errors whatsoever. I also don't want a time limit, just do a thing when it gets one reaction. Current code:

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

message.awaitReactions(filter, { max: 1})
    .then(collected => {
        const reaction = collected.first();

        if (reaction.emoji.name === '🗑') {
      sentMessage.delete(1000)
        } else {
            message.reply('you reacted with a thumbs down.');
        }
    })
    .catch(collected => {
        console.log(`After a minute, only ${collected.size} out of 4 reacted.`);
        message.reply('you reacted with neither a thumbs up, nor a thumbs down.');

Upvotes: 0

Views: 6335

Answers (1)

jackik
jackik

Reputation: 93

what does your filter look like? We con't see the first line of it. Your problem is that you try to check the emote twice. Once in the filter and then again in the function. Only use the filter here, or use the function if you want multiple emotes (i wouldn't recommend it).

my solution would look like this:

var message = msg.channel.send("test message");
    const filter = (reaction, user) => reaction.emoji.name === ':ok_hand:' //whatever emote you want to use, beware that .await.Reactions can only check a singel emote
    message.then(m=>{m.awaitReactions(filter, { max: 1})
        .then(collected => {
            console.log("do what ever");
            m.delete();//such as this
        })
        .catch(console.error);
     });

This works for me. Keep in mind that #awaitReactions isn't very versatile. If you want multiple ways of interacting with a message, you may want to look at #createReactionCollector which works the same way, but is triggered on every emote change instead.

I hope I helped.

Upvotes: 1

Related Questions