llms.txt: machine-readable documentation index. Markdown version of this page is also available.

Simple Robot 5.x Help

使用 Spring Boot

本页适合已有 Spring Boot 项目的读者,示例使用 Java 17 或更高版本。 如果使用 Spring Boot 2,请参考 使用 Spring Boot 2。

安装

准备一个 Spring Boot 3 项目,并添加 simbot starter:

implementation("love.forte.simbot:simbot-core-spring-boot-starter:5.0.0-Alpha2")
implementation 'love.forte.simbot:simbot-core-spring-boot-starter:5.0.0-Alpha2'
<dependency> <groupId>love.forte.simbot</groupId> <artifactId>simbot-core-spring-boot-starter</artifactId> <version>5.0.0-Alpha2</version> </dependency>

完整的项目准备和依赖说明见 Spring Boot。

使用

启用 simbot

在 Spring Boot 启动类上添加 @EnableSimbot:

import love.forte.simbot.spring.EnableSimbot import org.springframework.boot.autoconfigure.SpringBootApplication import org.springframework.boot.runApplication @EnableSimbot @SpringBootApplication(proxyBeanMethods = false) class MyApplication fun main(args: Array<String>) { runApplication<MyApplication>(*args) }
import love.forte.simbot.spring.EnableSimbot; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @EnableSimbot @SpringBootApplication public class MyApplication { public static void main(String[] args) { SpringApplication.run(MyApplication.class, args); } }

编写事件处理器

在 Spring 扫描范围内创建组件,并使用 @Listener 标记处理函数:

import love.forte.simbot.event.Event import love.forte.simbot.quantcat.common.annotations.Listener import org.springframework.stereotype.Component @Component class MyEventHandlers { @Listener suspend fun onEvent(event: Event) { println("收到事件: $event") } }
import love.forte.simbot.event.Event; import love.forte.simbot.quantcat.common.annotations.Listener; import org.springframework.stereotype.Component; @Component public class MyEventHandlers { @Listener public void onEvent(Event event) { System.out.println("收到事件: " + event); } }

Event 可监听多种事件。需要处理消息时,可以换成具体的消息事件类型,参见 事件监听与处理。

安装组件以及组件配置

选择 选择组件库 中的平台组件,按照它的手册添加依赖和 Ktor 客户端引擎。 组件提供平台相关的 Bot 和事件,具体的凭据与权限由目标平台决定。

注册Bot

多数官方组件支持通过配置文件自动注册 Bot。将对应平台的配置放入资源目录下的 simbot-bots/, 文件名以 .bot.json 结尾。配置内容请参考所选组件的快速开始:

默认情况下,starter 会扫描配置文件并启动注册的 Bot。扫描路径、自动启动等选项见 注册Bot。

运行或打包

启动 Spring Boot 应用,并在目标平台触发一个已订阅的事件。监听器输出“收到事件”表示事件已进入应用。 如果没有输出,请检查 Bot 是否启动、平台权限和事件订阅配置,再参考 常见问题。

应用启动后的其他配置方式、主动获取 Bot 和打包说明见 Spring Boot。

07 November 2026