javascript - discord.js Bot 重启前没有看到消息
问题描述
对不起,我的英语不好。
我想让一个角色对机器人做出反应我的问题是我的机器人在重启之前看不到消息发送
我接受了这段代码,但他没有看到对旧消息的反应。
我该怎么做才能让这段代码看到对旧消息的反应。
const Discord = require('discord.js');
const client = new Discord.Client({ partials: ['MESSAGE', 'CHANNEL', 'REACTION'] });
client.once('ready', () => {
console.log('Ready!');
});
client.on('messageReactionAdd', async (reaction, user) => {
if (reaction.message.partial) {
try {
await reaction.message.fetch();
}
catch (error) {
console.error('Something went wrong when fetching the message: ', error);
}
}
console.log(`${user.username} reacted with "${reaction.emoji.name}".`);
});
client.on('messageReactionRemove', async (reaction, user) => {
if (reaction.message.partial) {
try {
await reaction.message.fetch();
}
catch (error) {
console.error('Something went wrong when fetching the message: ', error);
}
}
console.log(`${user.username} removed their "${reaction.emoji.name}" reaction.`);
});
client.login('my token');
解决方案
除了检查反应消息是否是部分的,还要检查反应本身。
if (reaction.partial) {
try {
await reaction.fetch();
} catch (error) {
console.error('Something went wrong when fetching the reaction: ', error);
}
}
推荐阅读
- c - 用 C 编写大量文件后 Ubuntu 冻结
- javascript - 如何使用 Jest 在内部使用异步调用和调度测试动作减速器?
- javascript - 特定主导航链接的导航子菜单未正确显示
- python-3.x - 如何在pyspark中使用带有groupby的聚合表达式列表?
- android - 将现有的 android 应用导出为 aar(如库)
- jquery - 只有一个 div 使用 AJAX、jQuery 和 Circliful jQuery 插件填充
- xaml - UWP 中的 ItemsControl StatusChanged 等效项
- python - 如何在我的代码中实现回归模型图?
- asp.net - 在 IIS 上运行 Web 应用程序时出现 BadImageFormatException,但我的所有项目都是任何 CPU
- sql - 将 DATEDIFF 拆分为单独的月份