简体   繁体   中英

I'm trying to send a message after 2 persons react to a discord message using my discord bot

I am making a battle command for my discord bot where people can fight each other.
This is my current code:

//rng battl command (my whole life has lead up to this and bela cant stop me)
if(message.content.startsWith(`k!battle`)) {
var opponent = message.content.split(' ').slice(1).join(' ')
if(!opponent) return message.reply('Wait, who were you going to battle again?\nProper command useage: **k!battle <@username>**')
message.channel.send('Mentioned user, you have been challenged to a battle! Do you accept?')
message.channel.send(opponent)

//battle accept/deny
message.react('👍').then(() => message.react('👎'));
const filter = (reaction, user) => {
    return reaction.emoji.name === '👍' && user.id === message.author.id;
};
    
message.awaitReactions(filter, { max: 3, time: 30000, errors: ['time'] })
    .then(collected => message.channel.send('Let the battle commence! :KirbyPopcorn:'))
    .catch(collected => {
        message.channel.send(`Battle Expired.`);
    });
} 

Whenever the two users react to the message, nothing happens, but after the 30 seconds, the Battle Expired text shows up.
Please let me know if you spotted my mistake !

As @Sean said in the comments, your filter is misconfigured.

You're only allowing the command's author reactions to get through your collector, so you should replace your filter with this one:

const filter = (reaction, user) => { return reaction.emoji.name === '👍' && !user.bot; };

This one will allow anyone, except bots, to play the game!
I hope this fixes your issue!

PS: You should also lower the collector's max to 2;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM