【问题标题】:How to exclude the bot's reaction in the reaction collector如何在反应收集器中排除机器人的反应
【发布时间】:2022-02-05 09:36:32
【问题描述】:

我有一些旧代码,是我在 discord.js V12 期间编写的,它工作正常。 我最近更改了大多数需要更改的内容(v13 更改的内容)后,代码在我身上失败了,我制作了一个更简化的版本来查看问题是什么,似乎消息已发送到机器人,而不是任何对消息做出反应的人。

const { client, message } = require("discord.js")

module.exports = {
    name: "collect",
    description: "--",
    category: "info",

    async execute(message, args, client) {

        const newMsg = await message.channel.send("words")

        newMsg.react("✅")

        const filter = (reaction, user) => {
            return !user.bot
        };

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

        collector.on('collect', (reaction, user) => {
            user.send("it worked")
        });

    }
}

这是代码,我希望机器人在其中创建一条消息,在下面创建一个反应并允许用户对其作出反应,因此它可以获得用户的 id 并向他们发送消息。

但是,一旦我运行代码,它会发送消息,创建反应,并在下面抛出此错误;

DiscordAPIError: Cannot send messages to this user
    at RequestHandler.execute (E:\Github\Valorant-Curios-Tournaments\node_modules\discord.js\src\rest\RequestHandler.js:350:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async RequestHandler.push (E:\Github\Valorant-Curios-Tournaments\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
    at async UserManager.createDM (E:\Github\Valorant-Curios-Tournaments\node_modules\discord.js\src\managers\UserManager.js:58:18)
    at async ClientUser.send (E:\Github\Valorant-Curios-Tournaments\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.js:162:18) {
  method: 'post',
  path: '/users/852994509628768298/channels',
  code: 50007,
  httpStatus: 400,
  requestData: { json: { recipient_id: '852994509628768298' }, files: [] }
}

收件人的ID与bot的ID相同,所以我假设它没有用过滤器过滤掉bot的ID;

const filter = (reaction, user) => {
    return !user.bot === message.author.id;
};

任何帮助将不胜感激,谢谢。

【问题讨论】:

    标签: javascript discord discord.js


    【解决方案1】:

    没关系,我真的很笨

    过滤器在对象中。

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

    要解决这个问题,我只需要做到这一点

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

    【讨论】:

      猜你喜欢
      • 2019-06-01
      • 2020-08-12
      • 2021-12-18
      • 1970-01-01
      • 2021-10-10
      • 1970-01-01
      • 1970-01-01
      • 2022-10-30
      • 2021-11-14
      相关资源
      最近更新 更多