如何使removeCollector上的reactCollector工作? [英] How can I make a reactionCollector on a remove event work?

查看:67
本文介绍了如何使removeCollector上的reactCollector工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在研究一款不和谐的机器人.在这里,我开始一个 reactionCollector .收集到反应后,它会做一些事情;移除反应时,它应该做其他事情.

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')
  });

从不调用remove事件.有人知道为什么会这样吗?我在哪里弄错了?

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

推荐答案

使您的

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 });

此外,在处理ID时要小心(雪花),它们始终是String的类型.在您的代码中,您尝试查看 user.id 是否不等于数字(顺便说一句,确实是一个很大的数字!),所以请不要忘记用引号将ID引起来.

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";

这篇关于如何使removeCollector上的reactCollector工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆