我目前正在使用不和谐的bot。我遇到的一个问题是,我无法找出发送邮件后如何让机器人等待用户回复的方法。

我也尝试阅读有关在此处使用RestAction的git文档:https://github.com/DV8FromTheWorld/JDA/wiki/7)-Using-RestAction,但似乎没有提及实现类似于discord.js的“ await”功能的任何内容

我尝试编码以模仿这种效果:

public class EventHandler extends ListenerAdapter {

        private static final String PREFIX = "&";
        public static String[] args;


        public void sendMessage(String s, GuildMessageReceivedEvent event) {
            event
                    .getChannel()
                    .sendMessage(s)
                    .queue();
        }

        public void onGuildMessageReceived (GuildMessageReceivedEvent event) {

            args = event
                    .getMessage()
                    .getContentRaw()
                    .split(" ");

        if (args[0].equalsIgnoreCase(PREFIX + "any_command")) {
            sendMessage("Type hello!");
            if (args[0].equalsIgnoreCase(PREFIX + "hello") {
               sendMessage("hello there!");
            }
        }
    }
}


主班:

import net.dv8tion.jda.core.AccountType;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.JDABuilder;


public class Main {

    public static void main(String[] args) throws Exception {
        JDA jda = new JDABuilder(AccountType.BOT)
                .setToken("token goes here")
                .setAutoReconnect(true).build();

        try {
            jda.addEventListener(new EventHandler());
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}


这不会注册在给出提示后键入的hello命令。我最好的猜测是该条件永远不会满足,因为原始条件会覆盖即将出现的条件(args [0]已经是any_command)
任何帮助,将不胜感激!

最佳答案

我建议使用JDA-Utilities(https://github.com/JDA-Applications/JDA-Utilities/)中的EventWaiter

快速查看源代码,看起来您需要这样的东西

EventWaiter waiter = new EventWaiter();
// SO wouldn't let me insert new lines for some reason.
waiter.waitForEvent(GuildMessageReceivedEvent.class, (event) -> event.getMessage().getContentRaw().equalsIgnoreCase("hello"), (event) -> event.getChannel().sendMessage("hello!").queue()));

10-01 22:16