How can I make a reactionCollector on a remove event work?

若如初见. 提交于 2021-02-10 14:44:26

问题


So, I am working on a discord bot. Here I start a reactionCollector. When a reaction is collected, it does something, and when the reaction is removed, it should do something else.

await message.channel.send(embed)
  then(async function (message) {
    await message.react('⚔')

    const filter = (reaction, user) => {
      return reaction.emoji.name === '⚔' && user.id != 705462496646922311
    };
    collector = message.createReactionCollector(filter);

    collector.on('collect', async (reaction, user) => {
      // Do something.
    });

    collector.on('remove', (reaction, user) => {
      // Do something.
    });
  })
  .catch(function() {
    message.channel.send('Error while adding the reaction. Try again')
  });

The remove event never gets called. Does anyone know why this happen? Where did I do a mistake?


回答1:


To make your ReactionCollector fire dispose and remove events you have to enable dispose in the CollectorOptions of your ReactionCollector just like that :

collector = message.createReactionCollector(filter, { dispose: true });

Also, be carefull when manipulating IDs (Snowflakes), they are always type of String. In your code you try to see if user.id is not equal to a number (really big number by the way!) so don't forget to surround IDs with quotes.

return reaction.emoji.name === '⚔' && user.id != "705462496646922311";


来源:https://stackoverflow.com/questions/61858152/how-can-i-make-a-reactioncollector-on-a-remove-event-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!