javascript - 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);
解决方案
您的过滤器似乎不正确,将其替换为:const filter = (reaction, user) => reaction.emoji.name === '' || reaction.emoji.name === '' && user.id === message.author.id;
推荐阅读
- python - 将 groupby 的总和作为 Pandas 中具有不同值的新列
- json - 将变量放入 render() return - React Native
- sql - 将奇数文本字符串更改为日期 SQL
- file-upload - 通过 jsdelivr CDN 加载 Github 项目
- stm32 - STM32 中带有 FreeRTOS 的 STOP2 模式
- python - 以递归方式使用产量
- javascript - LocalStorage 检查模式打开了多少次
- java - 仍然收到致命警报:bad_certificate,
- java - java尝试资源:空结果集
- gridview - Yii2 自定义操作栏问题