Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 正在等待使用discordJDA的消息未按预期工作_Java_Discord - Fatal编程技术网

Java 正在等待使用discordJDA的消息未按预期工作

Java 正在等待使用discordJDA的消息未按预期工作,java,discord,Java,Discord,我目前正在开发我的discord机器人。我遇到的一个问题是,我无法找到如何允许bot在发送消息后等待用户答复 我还尝试阅读了git文档中关于在这里使用RestAction的内容:但是它似乎没有提到任何关于实现类似discord.js的“wait”函数的内容 我试着编写代码来模拟这种效果: public class EventHandler extends ListenerAdapter { private static final String PREFIX = "&"

我目前正在开发我的discord机器人。我遇到的一个问题是,我无法找到如何允许bot在发送消息后等待用户答复

我还尝试阅读了git文档中关于在这里使用RestAction的内容:但是它似乎没有提到任何关于实现类似discord.js的“wait”函数的内容

我试着编写代码来模拟这种效果:

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]已经是任意_命令)
任何帮助都将不胜感激

我建议使用JDA实用程序()

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

EventWaiter=neweventwaiter();
//所以出于某种原因不让我插入新行。
waiter.waitForEvent(GuildMessageReceivedEvent.class,(event)->event.getMessage().getContentRaw().equalsIgnoreCase(“hello”),(event)->event.getChannel().sendMessage(“hello!”).queue());

我忘记添加的其他内容:您必须将
eventwater
作为事件侦听器添加到JDA<代码>jda.addEventListener(服务员)是的,我意识到,在阅读了更多关于这个问题的内容后,我将它实现到我的EventListener类中。不过非常感谢!