EventWaiter无法正常工作 – Java Discord API

huangapple go评论59阅读模式
英文:

EventWaiter doesn't work - Java Discord API

问题

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

// 向私信发送消息并启动方法
event.replyInDm("message", (message) -> {
  message.addReaction("\uD83D\uDD27").queue();
  initWaiter(message.getIdLong(), channel);
});

private void initWaiter(long messageId, PrivateChannel channel) {
  // 在具有与上述消息相同id的消息中等待特定反应(EMOTE)
  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) -> {
      // 如果上面的代码为真,则应该发生这种情况,但事实并非如此
      assert channel != null;
      channel.sendMessage("message").queue();
    }
  );
}
英文:

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

得分: 0

确保将您的EventWaiter作为监听器添加到您的JDABuilder中:

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

如果您将等待器注册为监听器,则可能会缺少所需的DIRECT_MESSAGE_REACTIONS意图,假设您正在运行最新版本的JDA。

英文:

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

huangapple
  • 本文由 发表于 2020年10月20日 00:41:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/64431681.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定