DreamVoid / MiraiMC

适用于Minecraft服务器的Mirai机器人
https://docs.miraimc.dreamvoid.me
GNU Affero General Public License v3.0
181 stars 15 forks source link

BotIsBeingMutedException异常无法处理,导致程序无法继续进行 #67

Closed 164ebr closed 2 years ago

164ebr commented 2 years ago

问题描述

机器人在群内处于全员禁言状态时“BotIsBeingMutedException: bot is being muted, remaining 0.0s seconds” 程序会在禁言的群那部分卡住没有继续执行(我写的一个遍历群 然后挨个群发送消息的功能 类似群发) 然后群发并不完整,在禁言的那个群停了下来,后台报错BotIsBeingMutedException,程序也停了

复现方法

List groups = MiraiBot.getBot(MiraiBot.getOnlineBots().get(0)).getGroupList(); for (Long group : groups) { MiraiBot.getBot(MiraiBot.getOnlineBots().get(0)).getGroup(group).sendMessageMirai(“测试”); }

版本类型

截图

服务器日志

[15:54:12] [Server thread/WARN]: [MiraiMCBroadcast] Task #11 for MiraiMCBroadcast v1.0-SNAPSHOT generated an exception
net.mamoe.mirai.contact.BotIsBeingMutedException: bot is being muted, remaining 0.0s seconds
        at net.mamoe.mirai.internal.contact.SendMessageHandler.sendMessagePacket(SendMessageHandler.kt:175) ~[?:?]
        at net.mamoe.mirai.internal.contact.SendMessageHandler$sendMessagePacket$1.invokeSuspend(SendMessageHandler.kt) ~[?:?]
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) ~[?:?]
        at kotlinx.coroutines.internal.ScopeCoroutine.afterResume(Scopes.kt:33) ~[?:?]
        at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:102) ~[?:?]
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46) ~[?:?]
        at kotlinx.coroutines.DispatchedTaskKt.resume(DispatchedTask.kt:178) ~[?:?]
        at kotlinx.coroutines.DispatchedTaskKt.dispatch(DispatchedTask.kt:166) ~[?:?]
        at kotlinx.coroutines.CancellableContinuationImpl.dispatchResume(CancellableContinuationImpl.kt:397) ~[?:?]
        at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl(CancellableContinuationImpl.kt:431) ~[?:?]
        at kotlinx.coroutines.CancellableContinuationImpl.resumeImpl$default(CancellableContinuationImpl.kt:420) ~[?:?]
        at kotlinx.coroutines.CancellableContinuationImpl.resumeWith(CancellableContinuationImpl.kt:328) ~[?:?]
        at kotlinx.coroutines.ResumeAwaitOnCompletion.invoke(JobSupport.kt:1412) ~[?:?]
        at kotlinx.coroutines.JobSupport.completeStateFinalization(JobSupport.kt:318) ~[?:?]
        at kotlinx.coroutines.JobSupport.tryFinalizeSimpleState(JobSupport.kt:295) ~[?:?]
        at kotlinx.coroutines.JobSupport.tryMakeCompleting(JobSupport.kt:856) ~[?:?]
        at kotlinx.coroutines.JobSupport.makeCompleting$kotlinx_coroutines_core(JobSupport.kt:806) ~[?:?]
        at kotlinx.coroutines.CompletableDeferredImpl.complete(CompletableDeferred.kt:92) ~[?:?]
        at net.mamoe.mirai.internal.network.handler.NetworkHandlerSupport.collectReceived$mirai_core(NetworkHandlerSupport.kt:78) ~[?:?]
        at net.mamoe.mirai.internal.network.impl.netty.NettyNetworkHandler$PacketDecodePipeline$send$1.invokeSuspend(NettyNetworkHandler.kt:178) ~[?:?]
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) ~[?:?]
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) ~[?:?]
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163) ~[AbstractEventExecutor.class:4.1.9.Final]
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:403) ~[SingleThreadEventExecutor.class:4.1.9.Final]
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:442) ~[NioEventLoop.class:4.1.9.Final]
        at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858) ~[SingleThreadEventExecutor$5.class:4.1.9.Final]
        at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144) ~[DefaultThreadFactory$DefaultRunnableDecorator.class:4.1.9.Final]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_301]

额外说明

或许是其他问题(我也不清楚= =

164ebr commented 2 years ago

总之就是加一个判断机器人是否被禁言的功能即可

DreamVoid commented 2 years ago

其实我早就发现这个问题了,我也很纳闷为什么要抛个错误。然后我看了代码发现我只提供了检测他人是否被禁言的方法.. 就目前来说你有两种方案:用反射或者其他手段把机器人QQ获取MiraiNormalMember然后调用isMuted方法。或者用新线程调用发送消息,这样线程之间互不干扰。 我等一下可能会发1.5.3,也可能放到1.6里发。

164ebr commented 2 years ago

另外 ,也会出现这种错误“java.lang.IllegalStateException: Send message failed: MessageSvcPbSendMsg.Response.Failed(resultType=110, errorCode=0, errorMessage=发送失败,你已被移出该群,请重新加群。)”

类似你在手机QQ点开一个群,QQ给你弹出 “你已离开此群” 这样的弹窗

DreamVoid commented 2 years ago

1.5.3 发布后,请使用 isBotMuted()