【求助】尝试在群里执行戳一戳的时候报错
-
NormalMember member = (NormalMember) e.getFrom(); member.sendMessage("就你会戳吗?"); MemberNudge memberNudge = new MemberNudge((NormalMember) e.getFrom()); memberNudge.sendTo((Contact) e.getFrom());
尝试回复群成员并戳一戳他们
尝试执行这一长串的时候报错,同时Bot下线net.mamoe.mirai.event.ExceptionInEventHandlerException: Exception in EventHandler …… Caused by: java.lang.reflect.InvocationTargetException at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at net.mamoe.mirai.internal.event.JvmMethodListenersInternalKt.registerEventHandler$callMethod$invokeWithErrorReport(JvmMethodListenersInternal.kt:140) Caused by: java.lang.IllegalStateException: NetworkHandler is already closed. …… Suppressed: kotlinx.coroutines.TimeoutCancellationException: Timed out waiting for 5000 ms
并不是特别理解,会不会是我的代码问题?
-
奇怪,没法复现
ps:我的代码写错了,应为:
Group group = (Group) e.getSubject();
group.sendMessage("就你会戳吗?");
MemberNudge memberNudge = new MemberNudge((NormalMember) e.getFrom());
memberNudge.sendTo((Contact) e.getFrom());
ps:ps:这段代码好像并不能在群里戳群成员,而是私聊并戳一戳 -
代码改成了
Group group = (Group) e.getSubject();
group.sendMessage("就你会戳吗?");
e.getFrom().nudge().sendTo(e.getSubject());
目的达到了
(看起来报错不是我的问题) -