Home > Mobile >  JDA Discord Bot - [ErrorResponseException] 10008: Unknown Message
JDA Discord Bot - [ErrorResponseException] 10008: Unknown Message

Time:01-16

despite being new to JDA I havent had any big problems till now, maybe I am just missing something crucial. To quickly explain what following code SHOULD do:

Whenever the bot gets started, the onGuildReady event creates an Object containing a loop which sends a single message to a specified channel and after 1 minute edits said message.

    @Override
    public void onGuildReady(GuildReadyEvent event) {
        System.out.println("ON GUILD READY:  "   event.getGuild());
        new AutoController(event, channelid);

    }

Now with my understanding, the guildReady event should enable me to send messages to specified channels in every guild my bot is connected to AND edit them or do stuff with them.


String messageId = null;
String channelId;

public AutoController(GuildReadyEvent event, String channelId){
        this.event = event;
        start();
    }



@Override
   public void run(){

     try {
        while (true) {
          sleep((long) timer);
            if(messageId == null){
              event.getGuild().getTextChannelById(channelId).sendMessage("A").queue();
              this.messageId = event.getGuild().getTextChannelById(channelId).getLatestMessageId();
            }else{
              event.getGuild().getTextChannelById(channelId).editMessageById(messageId,"B").queue();
            }
         }
      } catch (InterruptedException e) {
            throw new RuntimeException(e);
      }

  }

Sending a message whenever the bot goes online works, but as soon as it gets in the 2nd loop where the edit should happen, it throws me an ErrorResponseException saying the message is unkknown.

[ForkJoinPool.commonPool-worker-1] ERROR RestAction - RestAction queue returned failure: [ErrorResponseException] 10008: Unknown Message net.dv8tion.jda.api.exceptions.ContextException at net.dv8tion.jda.api.exceptions.ContextException.here(ContextException.java:54) at net.dv8tion.jda.api.requests.Request.<init>(Request.java:73) at net.dv8tion.jda.internal.requests.RestActionImpl.queue(RestActionImpl.java:200) at net.dv8tion.jda.api.requests.RestAction.queue(RestAction.java:572) at net.dv8tion.jda.api.requests.RestAction.queue(RestAction.java:538) at org.gsbunker.controller.AutoController.run(AutoController.java:45)

I really dont understand why the message is unknown, ive already checked that the messageid and channelid are not null when passed - still getting the same error. the code is slightly simplified for understanding purposes, if questions occur feel free to ask. pleeeeeeeaase help me and my brain <3

CodePudding user response:

Sitting back and relaxing your brain sometimes really is the best solution!

Putting the thread to sleep after queuing made sure that the message is online and ready for retrieval when executing the editMessage method

if(messageId == null){
   event.getGuild().getTextChannelById(channelId).sendMessage("A").queue();
   sleep(3000);
   this.messageId = event.getGuild().getTextChannelById(channelId).getLatestMessageId();
}else{
   event.getGuild().getTextChannelById(channelId).editMessageById(messageId,"B").queue();
}

after reviewing the documentation again, if found that the complete() method would be even better suited for a use case like this.

if(messageId == null){
   event.getGuild().getTextChannelById(channelId).sendMessage("A").complete();
   this.messageId = event.getGuild().getTextChannelById(channelId).getLatestMessageId();
}else{
   event.getGuild().getTextChannelById(channelId).editMessageById(messageId,"B").queue();
}

yeeaahh not that big of a problem if you clear your head and stop forgetting java basics, happy coding :D

  • Related