为什么 messageReactionAdd 什么都不做 discord.js

Art*_*iir 1 javascript discord.js

我正在尝试使用 node.js 编写一个不和谐的机器人,但是我在使用 messageReactionAdd 时遇到了问题我现在不知道为什么当我对表情符号做出反应时机器人什么都不做。

我的代码:

bot.on('messageReactionRemove', (reaction, user) => {
console.log("that work 1");
if(reaction.emoji.name === "white_check_mark") {
    console.log("that work 2");
}})
Run Code Online (Sandbox Code Playgroud)

Dan*_*iev 7

事件messageReactionAddmessageReactionRemove仅适用于缓存的消息。您需要在代码中添加原始事件以触发任何消息。 https://github.com/AnIdiotsGuide/discordjs-bot-guide/blob/master/coding-guides/raw-events.md


nak*_*dev 7

更新 2022。您可能需要添加缓存消息的意图GUILD_MESSAGES才能GUILD_MESSAGE_REACTIONS使其正常工作。

参考:https ://discordjs.guide/popular-topics/reactions.html#listening-for-reactions-on-old-messages

const client = new Client({
    intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MESSAGE_REACTIONS],
    partials: ['MESSAGE', 'CHANNEL', 'REACTION'],
});
Run Code Online (Sandbox Code Playgroud)