为什么在机器人在线之前发送消息时机器人不触发 messageReactionAdd 事件

Why bot doesn't fire messageReactionAdd event when the message was sent before the bot was online

这是我检查用户添加反应的事件:

const client = require("../index");

client.on('messageReactionAdd', async (reaction, user) => {
    if (user.bot) return;
    console.log(reaction.emoji.name);
});

可以正常使用,但是当机器人重新启动时,它无法获取之前发送的任何消息?

为什么以及如何解决?

如果您不启用部分结构,您的代码仅适用于缓存的消息,即连接机器人后发布的消息。对旧消息做出反应不会触发 messageReactionAdd 事件。如果您还想收听对旧消息的反应,则需要在实例化客户端时为 MESSAGECHANNELREACTION 启用部分结构,如下所示:

const client = new Discord.Client({
  intents: [/* YOUR INTENTS */],
  partials: ['MESSAGE', 'CHANNEL', 'REACTION'],
});

你需要partials:

const client = new Client({
    intents: ‘’, // your intents here
    partials: ['CHANNEL', 'GUILD_MEMBER', 'GUILD_SCHEDULED_EVENT', 'MESSAGE', 'REACTION', 'USER'],
});