我如何获取机器人消息 ID 并编辑消息 - Discord JDA Java
How can i get the Bot Message ID and edit the Message - Discord JDA Java
对于我的学校项目,我正在学习如何设置机器人。我想出了如何获取消息 ID 的消息。但是 ID 不是来自 Bot,他是从编写命令的作者那里获得的 ID。 :
if (content.equals("!dim")){
channel.sendMessage("TEST!").queue();
Message bot = event.getMessage();
long messageID = bot.getIdLong();
String s = String.valueOf(messageID);
System.out.print(s);
channel.editMessageById(messageID, "text").queue();
}
控制台错误:
914706361378557982[ForkJoinPool.commonPool-worker-19] ERROR RestAction - RestAction queue returned failure: [ErrorResponseException] 50005: Cannot edit a message authored by another user
net.dv8tion.jda.api.exceptions.ContextException
at net.dv8tion.jda.api.exceptions.ContextException.here(ContextException.java:54)
at net.dv8tion.jda.api.requests.Request.<init>(Request.java:71)
at net.dv8tion.jda.internal.requests.RestActionImpl.queue(RestActionImpl.java:197)
at net.dv8tion.jda.api.requests.RestAction.queue(RestAction.java:573)
at net.dv8tion.jda.api.requests.RestAction.queue(RestAction.java:539)
at MessageListener.onMessageReceived(MessageListener.java:68)
at net.dv8tion.jda.api.hooks.ListenerAdapter.onEvent(ListenerAdapter.java:483)
at net.dv8tion.jda.api.hooks.InterfacedEventManager.handle(InterfacedEventManager.java:96)
at net.dv8tion.jda.internal.hooks.EventManagerProxy.handleInternally(EventManagerProxy.java:88)
at net.dv8tion.jda.internal.hooks.EventManagerProxy.handle(EventManagerProxy.java:70)
at net.dv8tion.jda.internal.JDAImpl.handleEvent(JDAImpl.java:160)
at net.dv8tion.jda.internal.handle.MessageCreateHandler.handleInternally(MessageCreateHandler.java:123)
at net.dv8tion.jda.internal.handle.SocketHandler.handle(SocketHandler.java:36)
at net.dv8tion.jda.internal.requests.WebSocketClient.onDispatch(WebSocketClient.java:952)
at net.dv8tion.jda.internal.requests.WebSocketClient.onEvent(WebSocketClient.java:839)
at net.dv8tion.jda.internal.requests.WebSocketClient.handleEvent(WebSocketClient.java:817)
at net.dv8tion.jda.internal.requests.WebSocketClient.onBinaryMessage(WebSocketClient.java:991)
at com.neovisionaries.ws.client.ListenerManager.callOnBinaryMessage(ListenerManager.java:385)
at com.neovisionaries.ws.client.ReadingThread.callOnBinaryMessage(ReadingThread.java:276)
at com.neovisionaries.ws.client.ReadingThread.handleBinaryFrame(ReadingThread.java:996)
at com.neovisionaries.ws.client.ReadingThread.handleFrame(ReadingThread.java:755)
at com.neovisionaries.ws.client.ReadingThread.main(ReadingThread.java:108)
at com.neovisionaries.ws.client.ReadingThread.runMain(ReadingThread.java:64)
at com.neovisionaries.ws.client.WebSocketThread.run(WebSocketThread.java:45)
我可以从错误中看出我的 MessageId 不是来自机器人。无论如何可以从 Bot.MessageBot 中获取它。
如果您需要更多信息,我会尽快更新此 post。
我不确定你的问题是什么...你调用的方法将编辑给定 ID
的消息(你可以通过 [=11= 在任何消息事件中获取该 ID ],注意不要将其与 getMessageId()
混淆,因为它 returns 一个 String
而 editMessage()
需要一个 long
)。或者,您可以调用 Message.editMessage(String newText).queue()
(直接从您的 Message
对象)来执行编辑。为了检索上述对象,请使用任何 Message
事件中的 getMessage()
。如果您对此事仍有疑问,请查看the documentation。
对于我的学校项目,我正在学习如何设置机器人。我想出了如何获取消息 ID 的消息。但是 ID 不是来自 Bot,他是从编写命令的作者那里获得的 ID。 :
if (content.equals("!dim")){
channel.sendMessage("TEST!").queue();
Message bot = event.getMessage();
long messageID = bot.getIdLong();
String s = String.valueOf(messageID);
System.out.print(s);
channel.editMessageById(messageID, "text").queue();
}
控制台错误:
914706361378557982[ForkJoinPool.commonPool-worker-19] ERROR RestAction - RestAction queue returned failure: [ErrorResponseException] 50005: Cannot edit a message authored by another user
net.dv8tion.jda.api.exceptions.ContextException
at net.dv8tion.jda.api.exceptions.ContextException.here(ContextException.java:54)
at net.dv8tion.jda.api.requests.Request.<init>(Request.java:71)
at net.dv8tion.jda.internal.requests.RestActionImpl.queue(RestActionImpl.java:197)
at net.dv8tion.jda.api.requests.RestAction.queue(RestAction.java:573)
at net.dv8tion.jda.api.requests.RestAction.queue(RestAction.java:539)
at MessageListener.onMessageReceived(MessageListener.java:68)
at net.dv8tion.jda.api.hooks.ListenerAdapter.onEvent(ListenerAdapter.java:483)
at net.dv8tion.jda.api.hooks.InterfacedEventManager.handle(InterfacedEventManager.java:96)
at net.dv8tion.jda.internal.hooks.EventManagerProxy.handleInternally(EventManagerProxy.java:88)
at net.dv8tion.jda.internal.hooks.EventManagerProxy.handle(EventManagerProxy.java:70)
at net.dv8tion.jda.internal.JDAImpl.handleEvent(JDAImpl.java:160)
at net.dv8tion.jda.internal.handle.MessageCreateHandler.handleInternally(MessageCreateHandler.java:123)
at net.dv8tion.jda.internal.handle.SocketHandler.handle(SocketHandler.java:36)
at net.dv8tion.jda.internal.requests.WebSocketClient.onDispatch(WebSocketClient.java:952)
at net.dv8tion.jda.internal.requests.WebSocketClient.onEvent(WebSocketClient.java:839)
at net.dv8tion.jda.internal.requests.WebSocketClient.handleEvent(WebSocketClient.java:817)
at net.dv8tion.jda.internal.requests.WebSocketClient.onBinaryMessage(WebSocketClient.java:991)
at com.neovisionaries.ws.client.ListenerManager.callOnBinaryMessage(ListenerManager.java:385)
at com.neovisionaries.ws.client.ReadingThread.callOnBinaryMessage(ReadingThread.java:276)
at com.neovisionaries.ws.client.ReadingThread.handleBinaryFrame(ReadingThread.java:996)
at com.neovisionaries.ws.client.ReadingThread.handleFrame(ReadingThread.java:755)
at com.neovisionaries.ws.client.ReadingThread.main(ReadingThread.java:108)
at com.neovisionaries.ws.client.ReadingThread.runMain(ReadingThread.java:64)
at com.neovisionaries.ws.client.WebSocketThread.run(WebSocketThread.java:45)
我可以从错误中看出我的 MessageId 不是来自机器人。无论如何可以从 Bot.MessageBot 中获取它。 如果您需要更多信息,我会尽快更新此 post。
我不确定你的问题是什么...你调用的方法将编辑给定 ID
的消息(你可以通过 [=11= 在任何消息事件中获取该 ID ],注意不要将其与 getMessageId()
混淆,因为它 returns 一个 String
而 editMessage()
需要一个 long
)。或者,您可以调用 Message.editMessage(String newText).queue()
(直接从您的 Message
对象)来执行编辑。为了检索上述对象,请使用任何 Message
事件中的 getMessage()
。如果您对此事仍有疑问,请查看the documentation。