栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

第一章:基于 SpringBoot 快速搭建QQ机器人,并监听群事件

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

第一章:基于 SpringBoot 快速搭建QQ机器人,并监听群事件

第一章:基于 SpringBoot 快速搭建QQ机器人
    • 前言:知识与储备
      • 这个QQ机器人能干什么?
    • 第一步:搭建Maven项目环境
    • 第二步:编写pom文件
    • 第三步:编写启动类
    • 第四步:创建配置文件
    • 第五步:编写一个监听器并监听群消息
    • 第六步:启动项目
    • 可能遇到的问题:
      • 滑块验证
      • 遇到其他问题可加QQ群进行讨论
    • 参考文档

前言:知识与储备

根据框架来实现一个QQ机器人、阅读这篇文章你需要Java基础以及SpringBoot(方便快速集成一些框架)和Maven的基础。
详细参考此文档:https://www.yuque.com/simpler-robot/simpler-robot-doc/ehy6dz

这个QQ机器人能干什么?

他可以监听并发送或者回复好友消息和群消息(比如群的禁言、At群成员等等 … )
此框架并没有具体的功能,你需要自己写代码来实现你所需的功能。

第一步:搭建Maven项目环境


然后点击 完成

第二步:编写pom文件


    4.0.0

    org.example
    springboot-robot
    1.0-SNAPSHOT

    
        8
        8
        5.3.16
        8
        3.0.0.preview.8.1
        3.0.0.0.preview.3.1
        3.0.0.0.preview.2.2
    

    
    
        org.springframework.boot
        spring-boot-starter-parent
        
        2.6.6
         
    

    
        
        
            org.springframework.boot
            spring-boot-starter-web
        

        
        
            love.forte.simbot.boot
            simboot-core-spring-boot-starter
            ${simbot.version}
        

        
        
            love.forte.simbot.component
            simbot-component-tencent-guild-boot
            ${simbot-component-tcg.version}
        

        
        
            love.forte.simbot.component
            simbot-component-mirai-boot
            ${simbot-component-mirai.version}
        
    

    


    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    



第三步:编写启动类
package com.ityifan;

import love.forte.simboot.autoconfigure.EnableSimbot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;


@EnableSimbot
@SpringBootApplication
public class SpringBootRoBotApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringBootRoBotApplication.class, args);
    }
}

目前包结构如下图:

第四步:创建配置文件

第五步:编写一个监听器并监听群消息
package com.ityifan.listener;

import love.forte.simboot.annotation.Listener;
import love.forte.simbot.event.GroupMessageEvent;
import org.springframework.stereotype.Component;


@Component
public class GroupListener {

    
    @Listener
    public void repeat(GroupMessageEvent event){

        // 获取群成员的消息
        // getPlainText()为文本消息
        final String message = event.getMessageContent().getPlainText();

        //发送消息
        event.getGroup().sendBlocking(message);

    }

}

目前包结构:

第六步:启动项目

运行启动器的main方法即可

可能遇到的问题: 滑块验证




遇到其他问题可加QQ群进行讨论

QQ交流群连接:
群聊与艺术:https://www.yuque.com/simpler-robot/simpler-robot-doc/xklly8

参考文档

参考文档:https://www.yuque.com/simpler-robot/simpler-robot-doc/xygygt

ityifan 禁止转载

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/948854.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号