Java JDA如何检查消息是否早于2周

huangapple go评论136阅读模式
英文:

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 &lt; 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.

huangapple
  • 本文由 发表于 2020年10月3日 19:50:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/64183917.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定