project-mirai / mirai-api-http

Mirai HTTP API (console) plugin
GNU Affero General Public License v3.0
1.66k stars 343 forks source link

如何转发某条消息? #547

Closed BobH233 closed 2 years ago

BobH233 commented 2 years ago

如题,比如一个好友转发给机器人一个“合并的聊天记录”,现在我想把这条“合并的聊天记录”原封不动的直接转发到另一个群组里面,是否可以通过消息id的方式直接转发? 我现在的实现方法是将好友消息中messageChain的Forward节点记录下来,然后再以消息的形式发出去,但是有一定概率会出现错误,错误如图。是否有更好的实现方式,比如就像手机qq中长按转发一样。谢谢大佬! 21D0A520-EEF0-4734-A9EB-DDD29DB6E47D AC0774B2F0C48C0BD9CCD0E43B02A55A

BobH233 commented 2 years ago

附上出错信息

2022-02-28 23:00:05 E/Bot.2404716639: Exception on parsing packet.
java.lang.IllegalStateException: Exception in net.mamoe.mirai.internal.network.notice.priv.PrivateMessageProcessor@5245363f while processing packet Msg.
        at net.mamoe.mirai.internal.network.components.NoticeProcessorPipelineImpl.process$suspendImpl(NoticeProcessorPipeline.kt:241)
        at net.mamoe.mirai.internal.network.components.NoticeProcessorPipelineImpl$process$1.invokeSuspend(NoticeProcessorPipeline.kt)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith(SuspendFunctionGun.kt:194)
        at io.ktor.util.pipeline.SuspendFunctionGun.access$resumeRootWith(SuspendFunctionGun.kt:15)
        at io.ktor.util.pipeline.SuspendFunctionGun$continuation$1.resumeWith(SuspendFunctionGun.kt:89)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
        at io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith(SuspendFunctionGun.kt:194)
        at io.ktor.util.pipeline.SuspendFunctionGun.access$resumeRootWith(SuspendFunctionGun.kt:15)
        at io.ktor.util.pipeline.SuspendFunctionGun$continuation$1.resumeWith(SuspendFunctionGun.kt:89)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
        at io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith(SuspendFunctionGun.kt:194)
        at io.ktor.util.pipeline.SuspendFunctionGun.access$resumeRootWith(SuspendFunctionGun.kt:15)
        at io.ktor.util.pipeline.SuspendFunctionGun$continuation$1.resumeWith(SuspendFunctionGun.kt:89)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
        at io.ktor.util.pipeline.SuspendFunctionGun.resumeRootWith(SuspendFunctionGun.kt:194)
        at io.ktor.util.pipeline.SuspendFunctionGun.access$resumeRootWith(SuspendFunctionGun.kt:15)
        at io.ktor.util.pipeline.SuspendFunctionGun$continuation$1.resumeWith(SuspendFunctionGun.kt:89)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.IllegalStateException: Failed to download forward message `9PueBihpbRxwV19xPPJgXt2xwYVYeJL7SBOlYfi5k+g/s7T69sNe5DzcvUdRT1nk`
        at net.mamoe.mirai.internal.MiraiImpl.downloadForwardMessage$suspendImpl(MiraiImpl.kt:843)
        at net.mamoe.mirai.internal.MiraiImpl$downloadForwardMessage$1.invokeSuspend(MiraiImpl.kt)
        ... 25 more
Caused by: java.lang.IllegalStateException: Cannot download forward message
        at net.mamoe.mirai.internal.MiraiImpl.downloadMultiMsgTransmit(MiraiImpl.kt:1219)
        at net.mamoe.mirai.internal.MiraiImpl.access$downloadMultiMsgTransmit(MiraiImpl.kt:71)
        at net.mamoe.mirai.internal.MiraiImpl$downloadMultiMsgTransmit$1.invokeSuspend(MiraiImpl.kt)
        ... 25 more
Caused by: java.net.UnknownHostException: ssl.htdata.qq.com
        at java.base/java.net.InetAddress$CachedAddresses.get(InetAddress.java:801)
        at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1509)
        at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1367)
        at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1301)
        at okhttp3.Dns$Companion$DnsSystem.lookup(Dns.kt:49)
        at okhttp3.internal.connection.RouteSelector.resetNextInetSocketAddress(RouteSelector.kt:164)
        at okhttp3.internal.connection.RouteSelector.nextProxy(RouteSelector.kt:129)
        at okhttp3.internal.connection.RouteSelector.next(RouteSelector.kt:71)
        at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:205)
        at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:106)
        at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:74)
        at okhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.kt:255)
        at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:32)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
        at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
        at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
        at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
        at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
        at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:517)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
        ... 1 more
ryoii commented 2 years ago

方法是对的。这个报错应该是复杂的消息类型需要上传服务器的时候,出现了 dns 解析失败。

检查下 bot 运行的网络,配置一个有效的 dns 服务器再做尝试。也不排除是上传的域名有问题,如果尝试过后还有问题,建议将这个 issue 链接到 mriai-core 的仓库,让 core 排查下这个域名是否支持所有地区的网络

BobH233 commented 2 years ago

好的,谢谢