【问题标题】:Why bot doesn't fire messageReactionAdd event when the message was sent before the bot was online为什么在机器人在线之前发送消息时机器人不触发 messageReactionAdd 事件
【发布时间】:2023-02-08 05:13:08
【问题描述】:

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

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

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

它正在工作,但是当机器人重新启动时,它无法获取之前发送的任何消息?

为什么以及如何解决它?

【问题讨论】:

    标签: javascript node.js discord discord.js


    【解决方案1】:

    如果您不启用部分结构,则您的代码仅适用于缓存的消息;连接机器人后发布的。对旧消息做出反应不会触发 messageReactionAdd 事件。

    如果您还想收听对旧消息的反应,则需要在实例化客户端时为 MESSAGECHANNELREACTION 启用部分结构,如下所示:

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

    如果你使用的是 discord.js v14,你可以像这样使用它:

    const {
      Client,
      GatewayIntentBits,
      Partials,
    } = require('discord.js');
    
    const client = new Client({
      intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.GuildMessageReactions,
        GatewayIntentBits.MessageContent,
      ],
      partials: [
        Partials.Channel,
        Partials.Message,
        Partials.Reaction,
      ],
    });
    

    【讨论】:

      【解决方案2】:

      你需要partials:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-10-30
        • 2022-01-19
        • 2023-04-07
        • 2021-08-19
        • 2014-09-18
        • 2019-06-13
        • 1970-01-01
        • 2012-09-21
        相关资源
        最近更新 更多