EventWaiter doesn't work - Java Discord API

237 Views Asked by At

I'm trying to create an EventWaiter when someone add a reaction to a specific message with this code below, but it doesn't seems to work. i've already tried to fix every single thing that could be an error, nevertheless nothing happens. There are no errors displaying on console, it seems that the eventwaiter doesn't listen to the MessageReactionAdd class

private static final String EMOTE = "\uD83D\uDE39";

// send a message to Dm and starts the method
event.replyInDm("message", (message - > {
  message.addReaction("\uD83D\uDD27").queue();
  initWaiter(message.getIdLong(), channel);
}));

private void initWaiter(long messageId, PrivateChannel channel) {
// waiting for a specific reaction (EMOTE) in a message with the same id as the message above
  waiter.waitForEvent(
    MessageReactionAddEvent.class,
    (e) - > {
      MessageReaction.ReactionEmote emote = e.getReactionEmote();
      assert user != null;
      return e.getMessageIdLong() == messageId && EMOTE.equals(emote.getName()) && !emote.isEmote() && !user.isBot();
    },
    (e) - > {
// if the code above is true, this should happen, but it doesn't
      assert channel != null;
      channel.sendMessage("message").queue();
    }
  );
1

There are 1 best solutions below

0
On BEST ANSWER

make sure you add your EventWaiter as a listener in your JDABuilder:

JDABuilder.createDefault("token", intents)
          .addEventListeners(..., waiter)
          ...

if you register the waiter as a listener, you may be missing the required DIRECT_MESSAGE_REACTIONS intent, assuming you're running one of the newest versions of jda