For my school project i am learning how to set up a bot. I figured out how to get a message the Message ID. But the ID is not from the Bot, he get the ID from the Author who wrote the command. :
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(); }
Error in Console:
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)
I can tell from the Error that my MessageId is not from the Bot. Is there anyway to get it from the MessageBot from the Bot. If you need any more Information, i will update this post asap.
Advertisement
Answer
I’m not sure what your issue is… the method you’re calling will edit the message for the given ID
(you can get that ID in any message event through getMessageIdLong()
, and be careful not to mistake that with getMessageId()
, since it returns a String
and editMessage()
requires a long
). Alternatively, you can call Message.editMessage(String newText).queue()
(directly from your Message
object) to perform the editing. In order to retrieve the aforementioned object, use getMessage()
from any Message
event. If you still have any doubts regarding this matter, check out the documentation.