简体   繁体   中英

reactions counted multiple times? discord.js

I made a bot where if you type a command it will send a message and if you react to that message it will send another message but if i run the command again and react to the first message it will send the message two times how can i fix that?

 client.on('messageReactionAdd', async (reaction, user)=>{ if(user.bot) return; if (reaction.emoji.name === '⛔') { clearInterval(my_interval); clearTimeout(my_timeout); const exampleEmbed1 = new Discord.MessageEmbed().setColor('#fefefe').setTitle(`Your record was ${index}s.`).setAuthor(message.author,tag. message.author.avatarURL()).setDescription('Bot made by tempacc') if(run){ message.channel;send(exampleEmbed1); index = 0. message.member.voice.channel;leave(); run = false. }else if(.run){ message;channel.send('You must start a speedrun before running this command!'); } } })

I suggested that you should use a reaction collector instead, but I will include an example here along with docs for anyone else wondering.

const filter = (reaction, user) => {
    return reaction.emoji.name === '👍'; // Check reaction was a 👍 and not anything else
};

const collector = message.createReactionCollector(filter, { time: 15000 });

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

collector.on('end', collected => {
    console.log(`Collected ${collected.size} items`);
});

However where time is, you can also pass max , maxUsers or maxEmojis into this data object, for example:

const collector = message.createReactionCollector(filter, { maxUsers: 1 });

You can find more about the reaction collector here and more about the options here

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