不和谐的机器人消息无法收集反应

时间:2020-04-28 22:14:36

标签: javascript node.js discord discord.js

一旦出现反应,我试图删除对我的机器人消息的反应,但是由于某种原因,我的行为似乎无法追查其原因。

我希望能够看到用户何时对回复消息做出反应,但我只能看到机器人何时对自己的消息做出反应以及用户何时对用户消息做出反应。我运行了我的代码(如下),并将“消息”发送到该频道,并在收到机器人的答复后,单击了我的消息和机器人消息上的响应。这是日志:

bot is ready
reaction by:  Lyon bot  on  reply
reaction by:  Lyon bot  on  reply
reaction by:  Lyon bot  on  reply
reaction by:  Lyon bot  on  reply
reaction by:  Virt  on  message
reaction by:  Virt  on  message

我希望能够看到reaction by: Virt on reply,但我从未看到。

const Discord = require('discord.js');
const bot = new Discord.Client();

const token = '*******';

bot.on('ready', () => {
    console.log('bot is ready');
});

bot.on('message', message => {
    if (message.content === 'message') {
        message.channel.send('reply');
    }

    message.react('?').then(() => message.react('?'));

    const filter = (reaction, user) => {
        return ['?', '?'].includes(reaction.emoji.name) && user.id === message.author.id;
    };

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

    collector.on('collect', r => {
        console.log('reaction by: ', r.message.author.username, ' on ', r.message.content);
    });
});

bot.login(token);

1 个答案:

答案 0 :(得分:0)

您的过滤器似乎不正确,请替换为:const filter = (reaction, user) => reaction.emoji.name === '?' || reaction.emoji.name === '?' && user.id === message.author.id;