Why messageReactionAdd do nothing discord.js

后端 未结 4 457
半阙折子戏
半阙折子戏 2020-12-10 23:19

I want to say that I am French, and I apologize for the mistakes.

I try to code a discord bot with node.js, but i have a problem with messageReactionAdd i don\'t now

相关标签:
4条回答
  • 2020-12-10 23:49

    The message must be cached before it will work. Any messages that come in while your bot is open will automatically get cached, but if it's for a specific older message, you can use:

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

    to cache it. After doing this (each time your script is run) you will receive reaction events for that message.

    0 讨论(0)
  • 2020-12-10 23:50

    Events messageReactionAdd and messageReactionRemove working only for cached messages. You need add raw event to your code for trigger any message. https://github.com/AnIdiotsGuide/discordjs-bot-guide/blob/master/coding-guides/raw-events.md

    0 讨论(0)
  • 2020-12-11 00:04

    You should listen to the messageReactionAdd event.
    Keep also in mind that ReactionEmoji.name is the Unicode for that emoji: you can get the Unicode symbol by writing a backslash before the emoji, like \:joy:. The Unicode for :white_check_mark: is ✅.

    This should be your code:

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

    This will work on every cached message, if you want it to work only on a specific message, try using Message.awaitReactions() or Message.createReactionCollector()

    0 讨论(0)
  • 2020-12-11 00:05

    You are doing reaction remove and you need to use Unicode emojis - you can find these online and copy them

    0 讨论(0)
提交回复
热议问题