首页 > 解决方案 > Discord 机器人消息不收集反应

问题描述

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

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

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

标签: javascriptnode.jsdiscorddiscord.js

解决方案


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


推荐阅读