JDA如何通过ID获取消息

时间:2020-01-18 01:05:51

标签: java discord-jda

有没有一种方法,只需拥有他的ID和他的TextChannel ID?

我发现了这个:

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

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

1 个答案:

答案 0 :(得分:3)

您可以使用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();
});

也值得一看: