JDA如何通过ID获取消息

JDA how to get a message by ID

有没有办法只通过他的 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();
});

还值得一看: