【问题标题】:Discord bot message doesn't collect reactionsDiscord 机器人消息不收集反应
【发布时间】:2020-08-12 21:32:17
【问题描述】:

我正在尝试在收到反应后删除对我的机器人消息的反应,但由于某种原因,我遇到了一些我似乎无法追查其原因的行为。

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

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

【问题讨论】:

    标签: javascript node.js discord discord.js


    【解决方案1】:

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

    【讨论】:

    • 谢谢,这并没有完全解决问题,但它确实告诉了我问题的根源。
    猜你喜欢
    • 2020-03-13
    • 2017-11-01
    • 1970-01-01
    • 2021-12-18
    • 1970-01-01
    • 2019-09-16
    • 2021-04-20
    • 2020-07-29
    • 2021-10-27
    相关资源
    最近更新 更多