我正在使用Gradle在IntelliJ中开发一个不和谐的机器人,该机器人有两个选择并允许其他人投票。但是,在使用投票命令之后,我找不到一种让其听取投票选择的方法。
public static void main(String[] args) throws LoginException {
JDABuilder builder = new JDABuilder(AccountType.BOT);
String token = "bot token";
builder.setToken(token);
builder.addEventListener(new Main());
builder.buildAsync();
}
@Override
public void onMessageReceived(MessageReceivedEvent event) {
System.out.println("We received a message from " +
event.getAuthor().getName() + ": " +
event.getMessage().getContentDisplay()
);
if (event.getMessage().getContentRaw().equals("vote uwu")) {
event.getJDA().addEventListener();
int choice1 = (int) (Math.random() * 6);
int choice2 = (int) (Math.random() * 6);
while (choice2 == choice1) {
choice2 = (int) (Math.random() * 6);
}
event.getChannel().sendMessage("1 - " + choices[choice1][0] + " | 2 - " + choices[choice2][0]).queue();
此处显示两个选项的消息,然后按类型1或2进行投票。我似乎无法通过后面的代码来投票,因为打印出来时分数保持不变,而且看不到投票确认消息。
if (event.getMessage().getContentRaw().equals("1")) {
choices[choice1][1] = Integer.toString((Integer.parseInt(choices[choice1][1]) + 2));
choices[choice2][1] = Integer.toString((Integer.parseInt(choices[choice2][1]) - 1));
event.getChannel().sendMessage("vote counted").queue();
}
else if (event.getMessage().getContentRaw().equals("2")) {
choices[choice2][1] = Integer.toString((Integer.parseInt(choices[choice2][1]) + 2));
choices[choice1][1] = Integer.toString((Integer.parseInt(choices[choice1][1]) - 1));
event.getChannel().sendMessage("vote counted").queue();
}
我假设我不能再使用MessageReceivedEvent参数中的“事件”,那么我将如何处理呢?