【问题标题】:Why messageReactionAdd do nothing discord.js为什么 messageReactionAdd 什么都不做 discord.js
【发布时间】:2019-04-05 04:54:24
【问题描述】:

我正在尝试使用 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");
}})

【问题讨论】:

    标签: javascript discord.js


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      消息必须被缓存才能工作。在您的机器人打开时收到的任何消息都会自动被缓存,但如果它是针对特定的旧消息,您可以使用:

      client.channels.get(CHANNELID).fetchMessage(MESSAGEID);
      

      缓存它。执行此操作后(每次运行脚本时),您将收到该消息的反应事件。

      【讨论】:

        【解决方案3】:

        2022 年更新。您可能需要为 GUILD_MESSAGESGUILD_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'],
        });
        

        【讨论】:

          【解决方案4】:

          你正在做反应删除,你需要使用 Unicode 表情符号 - 你可以在网上找到这些并复制它们

          【讨论】:

            【解决方案5】:

            您应该收听messageReactionAdd 事件。
            还要记住,ReactionEmoji.name 是该表情符号的 Unicode:您可以通过在表情符号前写一个反斜杠来获得 Unicode 符号,例如 \:joy::white_check_mark: 的 Unicode 是 ✅。

            这应该是您的代码:

            bot.on('messageReactionAdd', (reaction, user) => {
              console.log("first check");
              if (reaction.emoji.name === "✅") {
                console.log("second check");
              }
            });
            

            这将适用于每条缓存的消息,如果您希望它仅适用于特定消息,请尝试使用 Message.awaitReactions()Message.createReactionCollector()

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2018-07-13
              • 1970-01-01
              • 1970-01-01
              • 2021-02-09
              • 2017-12-08
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多