MiraiForum

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

    Solved [Kotlin]请问各位在使用CompositeCommand时调用其它方法如何传入GroupMessageEvent

    开发交流
    2
    9
    125
    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.
    • Nekoer
      Nekoer 摸鱼 last edited by

      请问各位在使用CompositeCommand时调用其它方法如何传入GroupMessageEvent

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

        Console 本身与 bot 无关, console 也不靠 core 消息事件驱动, console也不实现 MemberCommandSenderOnMessage, 在脱离 bot 上下文的环境下你需要使用 Bot.getInstance() / Bot.instances.

        CommandSenderOnMessage 的注释写的很清楚, 只有该命令的触发者是来自在线聊天环境的时候 sender 才会实现 CommandSenderOnMessage, console 本身与在线聊天环境没有任何关系

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

          https://github.com/mamoe/mirai-console/discussions/292

          Nekoer 1 Reply Last reply Reply Quote 0
          • Nekoer
            Nekoer 摸鱼 @Karlatemp last edited by

            @karlatemp 通过命令行启动一个功能,然后向指定群发送消息,但是这个过程中获取到的机器人对象为null

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

              您的问题描述不清楚,我无法理解您在问什么

              Nekoer 1 Reply Last reply Reply Quote 0
              • Nekoer
                Nekoer 摸鱼 @Karlatemp last edited by Nekoer

                @karlatemp 在console中输入/xxx start后,无论是

                val event = (this as? CommandSenderOnMessage<*>)?.fromEvent
                

                还是

                val event = (this as? MemberCommandSenderOnMessage)?.fromEvent
                

                event.bot获取都是null

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

                  console与bot无关

                  Nekoer 1 Reply Last reply Reply Quote 0
                  • Nekoer
                    Nekoer 摸鱼 @Karlatemp last edited by Nekoer

                    @karlatemp

                    插件依赖2.7-M2
                    从console发送/xxx start启动一个功能 =>

                        @SubCommand("start","启动")
                        suspend fun CommandSender.start() {
                             val event = (this as? MemberCommandSenderOnMessage)?.fromEvent
                             xxx(event)
                             这里输出event为null
                             这里需要调用方法,这个方法会向指定的QQ群发送消息
                        }
                    

                    这个方法需要先判断是否是我需要的群,然后发送消息
                    所以我这里需要获取机器人的所有群的list。
                    这时候传进来的event无法获取所有群的list,event本身为null

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

                      Console 本身与 bot 无关, console 也不靠 core 消息事件驱动, console也不实现 MemberCommandSenderOnMessage, 在脱离 bot 上下文的环境下你需要使用 Bot.getInstance() / Bot.instances.

                      CommandSenderOnMessage 的注释写的很清楚, 只有该命令的触发者是来自在线聊天环境的时候 sender 才会实现 CommandSenderOnMessage, console 本身与在线聊天环境没有任何关系

                      Nekoer 1 Reply Last reply Reply Quote 0
                      • Nekoer
                        Nekoer 摸鱼 @Karlatemp last edited by

                        @karlatemp 非常感谢XD

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