MiraiForum

    • Register
    • Login
    • Search
    • Popular
    • Recent
    • Unsolved
    • Tags
    • Groups
    • 友情链接

    求助!MiraiConsole无法监听聊天的消息内容

    开发交流
    5
    11
    249
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • KJZH001
      KJZH001 童心未泯 last edited by

      问题描述

      这里是我从实列里抄出来的指令
      在console中执行没有问题

      4e908273-5506-4c13-9971-0d8385278910-`H{N26VQI}54QK_}89{H3KG.png

      不过在聊天中执行的时候返回的log仅仅只表明bot收到这么一条消息,然后就没有反应了

      25d0701a-394f-4593-9e1d-e68a53a07fb8-A50HM73F.png

      相关的代码

      override fun onEnable()
          {
              logger.info { "Plugin loaded" }
              // 注册指令
              MySimpleCommand.register()
              MyCompositeCommand.register()
              MyTestCmd.register()
              val PERMISSION_EXECUTE_1 by lazy {
                  PermissionService.INSTANCE.register(permissionId("execute1"), "注册权限的示例")
              }
          }
      
      object MyTestCmd : SimpleCommand(
          Mirai, "tell", "私聊",
          description = "Tell somebody privately",
      ) {
          @Handler // 标记这是指令处理器  // 函数名随意
          suspend fun CommandSender.handle(target: User, message: String) { // 这两个参数会被作为指令参数要求
              target.sendMessage(message)
          }
      }
      

      一些其他的相关问题

      在尝试使用权限这块的代码时IDE会返回错误
      9b7f4419-6634-4212-95af-4c9fcd893c9a-image.png

      在这里先提前感谢各位大佬的解答!

      1 Reply Last reply Reply Quote 0
      • RainChan
        RainChan 摸鱼 last edited by

        @Him188

        1 Reply Last reply Reply Quote 0
        • Him188
          Him188 last edited by

          你需要为用户分配权限,用户才能在聊天使用指令(还要安装插件 chat-command)
          https://github.com/mamoe/mirai-console#执行指令

          你需要先定义并注册权限才能使用
          https://github.com/Him188/mirai-console-example-plugin/blob/49e93bf12a5a87b16e65d6f8f6b48f0a6662c527/src/main/kotlin/org/example/my/plugin/MyPluginMain.kt#L46

          KJZH001 1 Reply Last reply Reply Quote 0
          • KJZH001
            KJZH001 童心未泯 @Him188 last edited by

            @him188 这个我是定义了的
            放在override fun onEnable()里

                    val PERMISSION_EXECUTE_1 by lazy {
                        PermissionService.INSTANCE.register(permissionId("execute1"), "注册权限的示例")
                    }
            

            顺便我有个问题想要请教一下,怎么引用第三方的jar包呢?
            我直接添加到 idea的文件->项目结构->库 里没有效果

            感谢解答

            Samarium150 1 Reply Last reply Reply Quote 0
            • Him188
              Him188 last edited by Him188

              与通常 gradle 项目一样引用,打包时使用 buildPlugin

              KJZH001 1 Reply Last reply Reply Quote 0
              • Samarium150
                Samarium150 ⭐2021⭐ @KJZH001 last edited by

                @kjzh001

                dependencies {
                    implementation("...")
                }
                

                把这个加到build.gradle.kts里就能引用了

                KJZH001 1 Reply Last reply Reply Quote 0
                • Karlatemp
                  Karlatemp last edited by

                  这边建议emmm, 配合kotlin相关的书籍写

                  1 Reply Last reply Reply Quote 0
                  • KJZH001
                    KJZH001 童心未泯 @Samarium150 last edited by

                    @samarium150 谢谢

                    1 Reply Last reply Reply Quote 0
                    • KJZH001
                      KJZH001 童心未泯 @Him188 last edited by

                      @him188 抱歉,可能是我的意思表达的不太明确
                      前面的那个问题我是指
                      我在override fun onEnable()里定义了PERMISSION_EXECUTE_1以后在下面的代码里引用还是会报错

                      1 Reply Last reply Reply Quote 0
                      • Karlatemp
                        Karlatemp last edited by

                        你代码的意思是在 onEnable 定义了一个 局部变量 而不是一个字段, 自然不能从别的地方引用, 建议读 《30分钟入土 kotlin》

                        KJZH001 1 Reply Last reply Reply Quote 0
                        • KJZH001
                          KJZH001 童心未泯 @Karlatemp last edited by

                          @karlatemp 我之前也确实没有往变量作用范围上面想
                          因为这里是直接从实列里抄下来的
                          30分钟入土 kotlin 我会去找时间看的,感谢解答

                          1 Reply Last reply Reply Quote 0
                          • 1 / 1
                          • First post
                            Last post
                          Powered by Mamoe Technologies & NodeBB | 友情链接 | 服务监控 | Contact