英文:
Java JDA How to make check if the messsage is older than 2 weeks
问题
当消息的时间超过2周时,我遇到了关于我的Discord机器人清除聊天命令的问题。我如何进行检查?我的意思是,如果它们的时间超过2周,如何在频道中发送随机消息,而不是显示此错误?
错误消息:
[JDA MainWS-ReadThread] ERROR net.dv8tion.jda.api.JDA - One of the EventListeners had an uncaught exception
java.lang.IllegalArgumentException: Message Id provided was older than 2 weeks. Id: 756212215564206290
at net.dv8tion.jda.internal.utils.Checks.check(Checks.java:43)
at net.dv8tion.jda.internal.entities.TextChannelImpl.deleteMessagesByIds(TextChannelImpl.java:140)
at net.dv8tion.jda.internal.entities.TextChannelImpl.deleteMessages(TextChannelImpl.java:125)
at cf.lionsquad.lionminus.command.impl.ClearCommand.execute(ClearCommand.java:68)
at com.jagrosh.jdautilities.command.Command.run(Command.java:323)
at com.jagrosh.jdautilities.command.impl.CommandClientImpl.onMessageReceived(CommandClientImpl.java:557)
at com.jagrosh.jdautilities.command.impl.CommandClientImpl.onEvent(CommandClientImpl.java:445)
at net.dv8tion.jda.api.hooks.InterfacedEventManager.handle(InterfacedEventManager.java:96)
at net.dv8tion.jda.internal.hooks.EventManagerProxy.handleInternally(EventManagerProxy.java:82)
at net.dv8tion.jda.internal.hooks.EventManagerProxy.handle(EventManagerProxy.java:69)
at net.dv8tion.jda.internal.JDAImpl.handleEvent(JDAImpl.java:150)
at net.dv8tion.jda.internal.handle.MessageCreateHandler.handleInternally(MessageCreateHandler.java:122)
at net.dv8tion.jda.internal.handle.SocketHandler.handle(SocketHandler.java:36)
at net.dv8tion.jda.internal.requests.WebSocketClient.onDispatch(WebSocketClient.java:948)
at net.dv8tion.jda.internal.requests.WebSocketClient.onEvent(WebSocketClient.java:835)
at net.dv8tion.jda.internal.requests.WebSocketClient.handleEvent(WebSocketClient.java:813)
at net.dv8tion.jda.internal.requests.WebSocketClient.onBinaryMessage(WebSocketClient.java:986)
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)
此外,我还检查了是否没有指定要删除的消息数量(如果是 /clear 0 或者只是 /clear):
if (amount < 0) {
this.incorrectArgument(event, 0, args[0]);
return;
}
英文:
I have problem with my discord bot's clear chat command, when the message is older than 2 weeks, I have this problem. How can i make check ? I mean how can I make it if they are older than 2 weeks, to send random message in the channel instead to show this error?
[JDA MainWS-ReadThread] ERROR net.dv8tion.jda.api.JDA - One of the EventListeners had an uncaught exception
java.lang.IllegalArgumentException: Message Id provided was older than 2 weeks. Id: 756212215564206290
at net.dv8tion.jda.internal.utils.Checks.check(Checks.java:43)
at net.dv8tion.jda.internal.entities.TextChannelImpl.deleteMessagesByIds(TextChannelImpl.java:140)
at net.dv8tion.jda.internal.entities.TextChannelImpl.deleteMessages(TextChannelImpl.java:125)
at cf.lionsquad.lionminus.command.impl.ClearCommand.execute(ClearCommand.java:68)
at com.jagrosh.jdautilities.command.Command.run(Command.java:323)
at com.jagrosh.jdautilities.command.impl.CommandClientImpl.onMessageReceived(CommandClientImpl.java:557)
at com.jagrosh.jdautilities.command.impl.CommandClientImpl.onEvent(CommandClientImpl.java:445)
at net.dv8tion.jda.api.hooks.InterfacedEventManager.handle(InterfacedEventManager.java:96)
at net.dv8tion.jda.internal.hooks.EventManagerProxy.handleInternally(EventManagerProxy.java:82)
at net.dv8tion.jda.internal.hooks.EventManagerProxy.handle(EventManagerProxy.java:69)
at net.dv8tion.jda.internal.JDAImpl.handleEvent(JDAImpl.java:150)
at net.dv8tion.jda.internal.handle.MessageCreateHandler.handleInternally(MessageCreateHandler.java:122)
at net.dv8tion.jda.internal.handle.SocketHandler.handle(SocketHandler.java:36)
at net.dv8tion.jda.internal.requests.WebSocketClient.onDispatch(WebSocketClient.java:948)
at net.dv8tion.jda.internal.requests.WebSocketClient.onEvent(WebSocketClient.java:835)
at net.dv8tion.jda.internal.requests.WebSocketClient.handleEvent(WebSocketClient.java:813)
at net.dv8tion.jda.internal.requests.WebSocketClient.onBinaryMessage(WebSocketClient.java:986)
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)
Also I have check if there is not specified amount to message delete (if its /clear 0 or just /clear) :
if (amount < 0) {
this.incorrectArgument(event, 0, args[0]);
return;
}
答案1
得分: 0
有一种方法叫做 event.getMessage().getTimeCreated();
。
但在清除这些消息的情况下,这种情况是不会发生的。
英文:
There is a method which exists called event.getMessage().getTimeCreated();
But that wouldn't happen in the case when you are purging those messages.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论