JDA如何通过ID获取消息

Ayf*_*fri 3 java discord-jda

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

我找到了这个 :

Message message = TextChannel.getHistory().getMessageById(String id);
Run Code Online (Sandbox Code Playgroud)

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

Min*_*inn 5

您可以使用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();
});
Run Code Online (Sandbox Code Playgroud)

也值得一看:

  • MessageChannel可以是PrivateChannel或TextChannel,TextChannel是MessageChannel和GuildChannel。文本频道!= 私人频道 (2认同)