【问题标题】:How can I make a reactionCollector on a remove event work?如何使reactionCollector 对remove 事件起作用?
【发布时间】:2020-09-03 13:49:43
【问题描述】:

所以,我正在开发一个不和谐的机器人。在这里,我开始一个reactionCollector。当一个反应被收集时,它会做一些事情,当反应被移除时,它应该做其他事情。

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 事件。有谁知道为什么会这样?我哪里做错了?

【问题讨论】:

  • 我很确定第二行应该是.then() 而不是then()
  • 复制粘贴错误!对不起。

标签: javascript bots discord.js


【解决方案1】:

要使您的ReactionCollector 触发disposeremove 事件,您必须在CollectorOptionsCollectorOptions 中启用dispose,就像这样:

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

另外,在操作 ID (Snowflakes) 时要小心,它们始终是字符串类型。在您的代码中,您尝试查看 user.id 是否不等于一个数字(顺便说一下,这个数字真的很大!)所以不要忘记用引号将 ID 括起来。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-25
    • 1970-01-01
    • 2014-10-25
    • 2017-10-25
    • 1970-01-01
    相关资源
    最近更新 更多