好吧,我已经尝试了4个小时来解决这个问题
我的main.java是:
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import javax.security.auth.login.LoginException;
public class Main {
public static void main(String[] args){
JDABuilder jdaBuilder = JDABuilder.createDefault("token");
JDA jda = null;
PingPong pingPong = new PingPong();
jdaBuilder.addEventListeners(pingPong);
try {
jda = jdaBuilder.build();
} catch (LoginException e){
e.printStackTrace();
}
}
}
我的PingPong.java是:
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
public class PingPong extends ListenerAdapter {
@Override
public void onMessageReceived(MessageReceivedEvent e) {
if (e.getMessage().getContentRaw().equals("!ping")) {
e.getChannel().sendMessage("pong").queue();
}
}
}
我一直在像9(e.getChannel()。sendMessage(“ pong”)。queue();)
错误:
java: cannot access java.util.function.Consumer
class file for java.util.function.Consumer not found
我该如何解决?香港专业教育学院只是想发出一个测试命令,看看它是否能有效帮助
idk,如果与此有关但我正在使用 智慧 和即时通讯使用的是jda版本4.2.0_168
答案 0 :(得分:0)
您可以通过执行以下操作来清理主类。
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import javax.security.auth.login.LoginException;
public class Main {
public static void main(String[] args) {
try {
JDA jda = JDABuilder.createDefault("TOKEN")
.addEventListeners(new pingPong())
.build();
} catch (LoginException e) {
e.printStackTrace();
}
}
}
还请查看proper naming conventions in java,尤其是如何正确命名类。