【问题标题】:JDA how to get a message by IDJDA如何通过ID获取消息
【发布时间】:2020-05-04 21:23:55
【问题描述】:

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

我发现了这个:

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

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

【问题讨论】:

  • getHistory 不是静态方法,getMessageById 不能抛出该异常。

标签: java discord-jda


【解决方案1】:

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

也值得一看:

【讨论】:

  • 哦,非常感谢!我有一个问题,TextChannel 和 MessageChannel 有什么区别?
  • 一个MessageChannel可以是PrivateChannel或者TextChannel,TextChannel是MessageChannel和GuildChannel。 TextChannel != PrivateChannel
  • 当消息将由机器人自己发送时,我如何知道消息的 id?
猜你喜欢
  • 2021-03-06
  • 2020-10-20
  • 2022-01-05
  • 1970-01-01
  • 2013-04-02
  • 2017-12-08
  • 2018-09-01
  • 2014-09-26
  • 1970-01-01
相关资源
最近更新 更多