【问题标题】:Discord.js: How to send a message and collect reactions from itDiscord.js:如何发送消息并从中收集反应
【发布时间】:2019-12-18 11:51:33
【问题描述】:

我希望 discord.js 机器人在执行命令时发送消息,对其做出反应,然后捕获用户的所有反应以执行某些操作,例如响应它们。反应不应有时间限制。我还应该提到我正在使用命令处理程序,并且消息是从 index.js 以外的另一个文件发送的(甚至应该在其中发生收集)。

我尝试做一个收集器,但无论我怎么做,收集器变量都没有定义或不起作用。我知道它应该是一个事实的收集器。

为复选标记表情符号制作过滤器:

  return reaction.emoji.name === `✅` && user.id === call.message.author.id;
}

试图捕捉命令块本身之外的反应(因为如果我在块中这样做,事件将不起作用:

collector.on(`collect`, (reaction, reactionCollector) => {
    console.log(`Caught ${reaction.emoji.name}`);
});

我得到的错误几乎是意料之中的,但我想解决这个问题:

collector.on(`collect`, (reaction, reactionCollector) => {
^

ReferenceError: collector is not defined

也许是一个全局变量或设置消息 id 然后获取?帮帮我。

【问题讨论】:

标签: javascript node.js discord.js


【解决方案1】:

为什么不在你的 command.js 中包含 Collector?

 const time = 60000 //amount of time to collect for in milliseconds

 receivedMessage.channel.send("Hello World")
 .then(async function (message) {
      await message.react('✅')
      const filter = (reaction, user) => {
           return //YOUR FILTER HERE;
      };

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

      collector.on('collect', (reaction, reactionCollector) => {
           //do stuff
      });
 });

【讨论】:

    猜你喜欢
    • 2020-05-07
    • 2020-12-03
    • 1970-01-01
    • 2020-12-30
    • 1970-01-01
    • 2023-03-18
    • 2021-03-31
    • 2018-04-12
    • 2018-04-03
    相关资源
    最近更新 更多