有没有办法只通过他的 ID 和他的 TextChannel ID 来获取消息?

我找到了这个 :

Message message = TextChannel.getHistory().getMessageById(String id);

但它只是抛出一个错误:net.dv8tion.jda.api.exceptions.ErrorResponseException: 10008: Unknown Message

最佳答案

您可以使用 MessageChannel#retrieveMessageById(id) :

channel.retrieveMessageById(id).queue((message) -> {
// use the message here, its an async callback
    message.addReaction(reaction).queue();
    message.editMessage("bleh").queue();
    System.out.println("Message Content: " + message.getContentDisplay());
}, (failure) -> {
// if the retrieve request failed this will be called (also async)
    if (failure instanceof ErrorResponseException) {
        ErrorResponseException ex = (ErrorResponseException) failure;
        if (ex.getErrorResponse() == ErrorResponse.UNKNOWN_MESSAGE) {
            // this means the message doesn't exist
            channel.sendMessage("That message doesn't exist !").queue();
        }
    }
    failure.printStackTrace();
});

也值得一看:
  • editMessageById
  • deleteMessageById
  • getIterableHistory
  • addReactionById
  • 关于java - JDA如何通过ID获取消息,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59796672/

    10-12 05:52