英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论