【问题标题】:EventWaiter - Java Discord APIEventWaiter - Java Discord API
【发布时间】: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);
                }
            );
        }

【问题讨论】:

    标签: java discord


    【解决方案1】:

    最好的做法是不要存储 JDA 对象,例如通道,因为将它们的 ID 比较为 long 会更好。这可能就是问题所在。尝试e.getChannel().getIdLong() == event.getChannel().getIdLong() 否则,我猜它是您的方法之一,例如imageCreatorplayedWordsWrite

    【讨论】:

      猜你喜欢
      • 2021-02-02
      • 1970-01-01
      • 2020-12-27
      • 2018-02-25
      • 2020-12-01
      • 2020-12-12
      • 2021-08-11
      • 2019-04-22
      • 2020-12-30
      相关资源
      最近更新 更多