简体   繁体   中英

Discord js v12 Send message if someone reacts to embed

I'm currently making a discord bot using discord.js v12 (yes 12 not 13), I made a command that the bot sends an embed and reacts to it, in the filter I set the max to 2 (max: 2, ...). I want that every time someone reacts with this embed that like his name will be send in the channel. My current concept is this(it's in a function because I don't want to but everything in the switch):

async function fun_2p() {
  const reactionMessage2p = await message.channel.send(embed2p);
  const filter2p = (reaction, user) => user.id !== bot;

  await reactionMessage2p.react('🍻')

  reactionMessage2p.awaitReactions( filter2p, {max: 2, time: 20000, errors: ['time'] }).then(collected => {
                    
  })
}

Right before the last }) should be the code for the answer (I guess).

Use Message#createReactionCollector instead, and listen for the collect event

const reactionMessage2p = await message.channel.send(embed2p);
const filter2p = (reaction, user) => user.id !== bot

await reactionMessage2p.react('🍻')

const collector = message.createReactionCollector(filter2p, {max: 2, time: 20000, errors: ['time'] })

collector.on("collect", (reaction, user) => {
  reaction.message.channel.send(`${user.tag} has just reacted to the message`)
})

You can change the message to whatever you want

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