project-mirai / mirai-demos

mirai-console的一些插件与教学
GNU Affero General Public License v3.0
83 stars 75 forks source link

demo运行时,接受群信息出错 #1

Closed yukinotech closed 4 years ago

yukinotech commented 4 years ago

demo源码

package net.mamoe.mirai.simpleloader

import kotlinx.coroutines.*
import net.mamoe.mirai.Bot
import net.mamoe.mirai.alsoLogin
import net.mamoe.mirai.event.subscribeMessages

suspend fun main() {
    val qqId = XXXXXXL//Bot的QQ号,需为Long类型,在结尾处添加大写L
    val password = "XXX"//Bot的密码
    val miraiBot = Bot(qqId, password).alsoLogin()//新建Bot并登录
    miraiBot.subscribeMessages {
        "你好" reply "你好!"
        case("at me") {
            reply(sender.at() + " 给爷爬 ")
        }

        (contains("test") or contains("刘老板")) {
            "刘老板太强了".reply()
        }
    }
    miraiBot.join() // 等待 Bot 离线, 避免主线程退出
}

能够正常登录,但是在接收群信息时,会出现下面的错误。同时无法根据demo里面的内容进行自动回复。日志如下:

Bot(358601743) 19:25:25 : Received: GroupMessage(group=XXXX, senderName=XXX, sender=XXX, permission=OWNER, message=tt)
Bot(358601743) 19:25:25 : An exception was thrown under a coroutine of Bot
Bot(358601743) 19:25:25 : An exception was thrown under a coroutine of Bot
Bot(358601743) 19:25:25 : An exception was thrown under a coroutine of Bot
java.lang.IllegalStateException: WeakRef is released
    at net.mamoe.mirai.utils.UnsafeWeakRef.get-impl(WeakRef.kt:22)
    at net.mamoe.mirai.utils.WeakRefKt.getValue-oCG-Uto(WeakRef.kt:33)
    at net.mamoe.mirai.qqandroid.MemberImpl.getQq(ContactImpl.kt)
    at net.mamoe.mirai.qqandroid.MemberImpl.getBot(ContactImpl.kt:264)
    at net.mamoe.mirai.qqandroid.MemberImpl.getBot(ContactImpl.kt:183)
    at net.mamoe.mirai.message.GroupMessage.getBot(GroupMessage.kt:38)
    at net.mamoe.mirai.simpleloader.IndexKt$main$$inlined$subscribeMessages$1$2.invokeSuspend(subscriber.kt:212)
    at net.mamoe.mirai.simpleloader.IndexKt$main$$inlined$subscribeMessages$1$2.invoke(subscriber.kt)
    at net.mamoe.mirai.event.internal.Handler$onEvent$2.invokeSuspend(InternalEventListeners.kt:59)
    at net.mamoe.mirai.event.internal.Handler$onEvent$2.invoke(InternalEventListeners.kt)
    at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:91)
    at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:154)
    at kotlinx.coroutines.BuildersKt.withContext(Unknown Source)
    at net.mamoe.mirai.event.internal.Handler.onEvent(InternalEventListeners.kt:59)
    at net.mamoe.mirai.event.internal.InternalEventListenersKt$callAndRemoveIfRequired$$inlined$forEachNode$lambda$1.invokeSuspend(InternalEventListeners.kt:165)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:561)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:727)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:667)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:655)
java.lang.IllegalStateException: WeakRef is released
    at net.mamoe.mirai.utils.UnsafeWeakRef.get-impl(WeakRef.kt:22)
    at net.mamoe.mirai.utils.WeakRefKt.getValue-oCG-Uto(WeakRef.kt:33)
    at net.mamoe.mirai.qqandroid.MemberImpl.getQq(ContactImpl.kt)
    at net.mamoe.mirai.qqandroid.MemberImpl.getBot(ContactImpl.kt:264)
    at net.mamoe.mirai.qqandroid.MemberImpl.getBot(ContactImpl.kt:183)
    at net.mamoe.mirai.message.GroupMessage.getBot(GroupMessage.kt:38)
    at net.mamoe.mirai.simpleloader.IndexKt$main$$inlined$subscribeMessages$1$2.invokeSuspend(subscriber.kt:212)
    at net.mamoe.mirai.simpleloader.IndexKt$main$$inlined$subscribeMessages$1$2.invoke(subscriber.kt)
    at net.mamoe.mirai.event.internal.Handler$onEvent$2.invokeSuspend(InternalEventListeners.kt:59)
    at net.mamoe.mirai.event.internal.Handler$onEvent$2.invoke(InternalEventListeners.kt)
    at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:91)
    at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:154)
    at kotlinx.coroutines.BuildersKt.withContext(Unknown Source)
    at net.mamoe.mirai.event.internal.Handler.onEvent(InternalEventListeners.kt:59)
    at net.mamoe.mirai.event.internal.InternalEventListenersKt$callAndRemoveIfRequired$$inlined$forEachNode$lambda$1.invokeSuspend(InternalEventListeners.kt:165)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:561)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:727)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:667)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:655)
java.lang.IllegalStateException: WeakRef is released
    at net.mamoe.mirai.utils.UnsafeWeakRef.get-impl(WeakRef.kt:22)
    at net.mamoe.mirai.utils.WeakRefKt.getValue-oCG-Uto(WeakRef.kt:33)
    at net.mamoe.mirai.qqandroid.MemberImpl.getQq(ContactImpl.kt)
    at net.mamoe.mirai.qqandroid.MemberImpl.getBot(ContactImpl.kt:264)
    at net.mamoe.mirai.qqandroid.MemberImpl.getBot(ContactImpl.kt:183)
    at net.mamoe.mirai.message.GroupMessage.getBot(GroupMessage.kt:38)
    at net.mamoe.mirai.simpleloader.IndexKt$main$$inlined$subscribeMessages$1$2.invokeSuspend(subscriber.kt:212)
    at net.mamoe.mirai.simpleloader.IndexKt$main$$inlined$subscribeMessages$1$2.invoke(subscriber.kt)
    at net.mamoe.mirai.event.internal.Handler$onEvent$2.invokeSuspend(InternalEventListeners.kt:59)
    at net.mamoe.mirai.event.internal.Handler$onEvent$2.invoke(InternalEventListeners.kt)
    at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:91)
    at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:154)
    at kotlinx.coroutines.BuildersKt.withContext(Unknown Source)
    at net.mamoe.mirai.event.internal.Handler.onEvent(InternalEventListeners.kt:59)
    at net.mamoe.mirai.event.internal.InternalEventListenersKt$callAndRemoveIfRequired$$inlined$forEachNode$lambda$1.invokeSuspend(InternalEventListeners.kt:165)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:561)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:727)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:667)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:655)
yukinotech commented 4 years ago

补充:好友之间1对1能够正常回复,群消息不行

Him188 commented 4 years ago

demo 使用的 core 版本太旧了, 稍等更新

yukinotech commented 4 years ago

demo 使用的 core 版本太旧了, 稍等更新

已替换成0.28.0,问题解决