JDA Discord 向消息添加反应
Posted
技术标签:
【中文标题】JDA Discord 向消息添加反应【英文标题】:JDA Discord Add Reaction To Message 【发布时间】:2021-03-11 16:16:39 【问题描述】:当我尝试对机器人发送的消息添加反应时遇到问题。这是我的代码以及我尝试添加反应时遇到的问题。
这个想法很简单。只是一个由机器人发送的投票命令+添加对它的反应,例如竖起大拇指和向下拇指:
“$poll This Is Example Poll”并在创建此投票后,添加反应
代码 -
@Override
protected void execute(CommandEvent event)
if (this.check(event))
return;
var args = event.getArgs().trim();
if (args.isEmpty())
this.incorrectUsage(event);
return;
var announcementFormat = this.getConfig().getMessages().get("pool-format")
.replaceAll("%message", args);
event.reply(announcementFormat);
event.getMessage().addReaction("✔").queue();
错误-
ERROR net.dv8tion.jda.api.requests.RestAction - RestAction queue returned failure: [ErrorResponseException] 10008: Unknown Message
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:563)
at net.dv8tion.jda.api.requests.RestAction.queue(RestAction.java:529)
at cf.lionsquad.lionminus.command.impl.PollCommand.execute(PollCommand.java:48)
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)
【问题讨论】:
【参考方案1】:你可以使用flatMap:
event.getChannel().sendMessage(announcementFormat)
.flatMap(message -> message.addReaction("✔"))
.queue();
而不是event.reply(announcementFormat)
。
您的代码当前尝试对用户发送的消息而不是您的机器人发送的消息添加反应。但是,该消息此时已被删除,这就是您收到 Unknown Message
错误的原因。
【讨论】:
非常有趣,感谢您的想法,但我怎样才能添加喜欢 2 个反应??? 我尝试了很多东西,没有任何效果,其中之一是:" .flatMap(message -> message.addReaction("✔"), message -> message.addReaction("emoji" )) " 不工作:/ 尝试使用 RestAction.allOf(action1, action2) 我需要把这个休息动作放在哪里? 我尝试使用“ .flatMap(RestAction.allOf(event.getMessage().addReaction("✔"),event.getMessage().addReaction("✔"))) ”,不工作.以上是关于JDA Discord 向消息添加反应的主要内容,如果未能解决你的问题,请参考以下文章