Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JDA如何通过ID获取消息_Java_Discord Jda - Fatal编程技术网

Java JDA如何通过ID获取消息

Java JDA如何通过ID获取消息,java,discord-jda,Java,Discord Jda,只有他的ID和TextChannelID才能获得信息吗 我发现: Message Message=TextChannel.getHistory().getMessageById(字符串id); 但它只是抛出一个错误:net.dv8tion.jda.api.exceptions.ErrorResponseException:10008:Unknown Message您可以使用: channel.retrieveMessageById(id).queue((消息)->{ //在这里使用消息,它是一

只有他的ID和
TextChannel
ID才能获得信息吗

我发现:

Message Message=TextChannel.getHistory().getMessageById(字符串id);
但它只是抛出一个错误:
net.dv8tion.jda.api.exceptions.ErrorResponseException:10008:Unknown Message
您可以使用:

channel.retrieveMessageById(id).queue((消息)->{
//在这里使用消息,它是一个异步回调
message.addReaction(reaction.queue();
message.editMessage(“bleh”).queue();
System.out.println(“消息内容:+Message.getContentDisplay());
},(失败)->{
//如果检索请求失败,将调用该请求(也是异步的)
if(错误响应异常的故障实例){
ErrorResponseException ex=(ErrorResponseException)故障;
如果(例如getErrorResponse()==ErrorResponse.UNKNOWN_消息){
//这意味着该消息不存在
channel.sendMessage(“该消息不存在!”).queue();
}
}
失败。printStackTrace();
});
也值得一看:


getHistory
不是一个静态方法,
getMessageById
无法引发该异常。非常感谢!我有一个问题,TextChannel和MessageChannel有什么区别?MessageChannel可以是PrivateChannel或TextChannel,TextChannel是MessageChannel和GuidChannel。文本频道!=PrivateChannel当消息将由bot本身发送时,我如何知道消息的id?