【发布时间】:2018-03-04 21:13:52
【问题描述】:
这是一个奇怪的具体问题,但我正在尝试让 JDA Utilities 中的 EventWaiter 工作。 (https://github.com/jagrosh/ExampleBot/tree/master/src/main/java/com/jagrosh/examplebot)
我设置了一个方法并且超时部分有效,但服务员似乎没有像预期的那样接收任何发送到 discord 的新消息,我不知道为什么。这是我所拥有的:
public static void askQuestions(int numLeft, MessageReceivedEvent event, String level) {
if(numLeft==0) {
Writer.listWords(event);
Writer.clearWords();
return;
}
//Get random line from text file and store in text.
text = Reader.fileReader(level);
//Get the question
word = getQuestion(text);
//Get the answer
ans = getAnswer(text, event);
//Write word to txt file to print out later at end of game.
Writer.playedWordsWrite(word, ans);
//Create image of word and send to discord
imageCreator(word, event);
//Set up waiter to get players' answers. Mention user who gets it right and then call the method again.
waiter.waitForEvent(MessageReceivedEvent.class,
//Make sure it's the right answer in the same channel
e -> e.getChannel().equals(event.getChannel()) && e.getMessage().getRawContent().equals(ans),
//Respond, inserting the name they listed into the response
e -> {
e.getChannel().sendMessage(e.getAuthor().getAsMention()+ " got it right!").queue();
askQuestions(numLeft-1, e, level);
},
//If the user takes more than 10 seconds, time out
7, TimeUnit.SECONDS, () -> {
event.getTextChannel().sendMessage("Correct answer: "+ans).queue();
askQuestions(numLeft-1, event, level);
}
);
}
【问题讨论】: