MiraiForum

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

    如何让bot启动时给指定账号发送一条消息

    开发交流
    5
    14
    267
    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.
    • ConstantineQAQ
      ConstantineQAQ last edited by

      如题,我想让我的bot在mcl启动成功之后给我的大号发送一条消息让我知道他启动成功了

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

        写一个插件,在onEnable中调用sendMessage方法

        cssxsh ConstantineQAQ 2 Replies Last reply Reply Quote 0
        • cssxsh
          cssxsh @Shennoter last edited by

          @Shennoter
          onEnable 中 自动登录并没有完成,不能获取 bot 实例

          应该是注册一个 BotOnlineEvent 的事件监听器
          然后在事件中获得 bot 实例,用这个实例 发消息

              @EventHandler
              suspend BotOnlineEvent.mark() {
                  bot.getFriend(xxxx).sendMessage(yyyy)
              }
          
          Shennoter 1 Reply Last reply Reply Quote 0
          • Shennoter
            Shennoter 摸鱼 @cssxsh last edited by

            @cssxsh 对不起,我没试过就说了😭,学到了

            1 Reply Last reply Reply Quote 0
            • ConstantineQAQ
              ConstantineQAQ @Shennoter last edited by

              @Shennoter 这个是要新写一个mirai-console吗

              Shennoter 1 Reply Last reply Reply Quote 0
              • Shennoter
                Shennoter 摸鱼 @ConstantineQAQ last edited by

                @ConstantineQAQ 不是,idea下载mirai插件,然后创建一个插件项目

                ConstantineQAQ 1 Reply Last reply Reply Quote 0
                • ConstantineQAQ
                  ConstantineQAQ @Shennoter last edited by

                  @Shennoter 哦哦,我还有个问题,就是新建了插件项目之后要监听事件做出响应的功能该写在哪里(是新建一个.kt文件吗?),我看那个帮助文档里面没有写

                  Shennoter 1 Reply Last reply Reply Quote 0
                  • Shennoter
                    Shennoter 摸鱼 @ConstantineQAQ last edited by

                    @ConstantineQAQ 建议新建一个kt文件

                    ConstantineQAQ 1 Reply Last reply Reply Quote 0
                    • ConstantineQAQ
                      ConstantineQAQ @Shennoter last edited by

                      @Shennoter 那我该在哪个文件夹里面新建这个.kt文件呢?46bbdc9d-478f-4702-96b6-b81b8f6739f2-image.png

                      Shennoter 1 Reply Last reply Reply Quote 0
                      • Shennoter
                        Shennoter 摸鱼 @ConstantineQAQ last edited by

                        @ConstantineQAQ src/main/kotlin
                        文件结构可以多看几个别人的项目学习一下

                        ConstantineQAQ 1 Reply Last reply Reply Quote 0
                        • ConstantineQAQ
                          ConstantineQAQ @Shennoter last edited by

                          @Shennoter 好的,我才刚刚接触这个bot,不是很了解,多谢解答

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

                            监听BotOnlineEvent,参考 https://github.com/StageGuard/SuperCourseTimetableBot/blob/main/src/main/kotlin/me/stageguard/sctimetable/PluginMain.kt#L48

                            1 Reply Last reply Reply Quote 0
                            • C
                              Cuveanst last edited by

                              主动发送消息
                              Long qqId = xxxxxxxxxx;
                              Bot.getInstances().get(0).getFriend(qqId).sendMessage("发送消息");

                              C 1 Reply Last reply Reply Quote 0
                              • C
                                Cuveanst @Cuveanst last edited by

                                @Cuveanst java

                                1 Reply Last reply Reply Quote 0
                                • Moved from 技术交流板块 by  Karlatemp Karlatemp 
                                • 1 / 1
                                • First post
                                  Last post
                                Powered by Mamoe Technologies & NodeBB | 友情链接 | 服务监控 | Contact