轻量级 QQ 机器人 SDK,专注于简洁、容易上手且稳定
Project description
✨ 轻量级 QQ 官方机器人 SDK,极简 API 设计,~6 行代码即可启动 ✨
简介
EasyBot 是一款专为 QQ 官方机器人平台打造的轻量级 Python SDK,定位为面向初级开发者的入门级框架。其核心理念是「简洁、易上手、稳定」,通过极简的 API 设计和完善的抽象层,让开发者能够以最少的代码量快速构建功能完备的 QQ 机器人应用。
核心特性
🚀 极简 API — ~6 行代码启动机器人,无需继承任何类
🎯 零继承装饰器范式 — @bot.on_guild_message 直接用,告别繁琐的 Client 子类重写
📦 最小依赖 — 仅需 aiohttp + pyyaml 两个第三方库,安装即用
🔧 三协议全支持 — WebSocket / Webhook / Remote Webhook 自由切换,适配任意部署环境
🌐 全场景消息覆盖 — 频道、群聊、C2C 私聊、频道私信四大场景一站搞定
💬 内置会话管理器 — Session + WaitFor 多轮对话原生支持,带超时回复与 GC 回收(业界独有)
🧩 插件自动加载 — 扫描目录自动注册指令与预处理器,开箱即用的插件生态
🎮 增强指令系统 — 正则匹配 / 管理员权限 / 短路机制 / 多场景隔离 / 预处理器五合一
⏰ 生命周期管理 — startup / shutdown / timer 三大内置事件,无需额外框架
🔒 沙箱环境支持 — 一键开启沙箱模式,安全调试不干扰线上机器人
🏷️ 现代 Python 语法 — 基于 Python 3.10+,完整类型提示,IDE 智能补全无忧
安装
pip install easybot-qq
快速开始
最简示例 — ~6 行启动机器人
from easybot import Bot, Model
bot = Bot(app_id="你的AppID", app_secret="你的AppSecret")
@bot.on_guild_message
async def on_message(msg: Model.GuildMessage) -> None:
await msg.reply("Hello World!")
bot.start()
公域机器人只会收到频道内 @它 的消息;请在频道中 @机器人进行测试。
最小错误处理(推荐)
from easybot import Bot, Model, APIError, NetworkError, RateLimitError
bot = Bot(app_id="你的AppID", app_secret="你的AppSecret")
@bot.on_guild_message
async def on_message(msg: Model.GuildMessage) -> None:
try:
await msg.reply(f"你说:{msg.treated_msg}")
except RateLimitError as e:
bot.logger.warning(f"触发频率限制:{e}")
except (APIError, NetworkError) as e:
bot.logger.error(f"回复失败:{e}")
bot.start()
异步启动(自行管理事件循环)
import asyncio
from easybot import Bot, Model
bot = Bot(app_id="你的AppID", app_secret="你的AppSecret")
@bot.on_guild_message
async def on_message(msg: Model.GuildMessage) -> None:
await msg.reply("Hello World!")
asyncio.run(bot.start_async())
多场景消息处理 — 一个 Bot 打天下
from easybot import Bot, Model
bot = Bot(app_id="你的AppID", app_secret="你的AppSecret")
@bot.on_guild_message
async def handle_guild(msg: Model.GuildMessage):
await msg.reply(f"频道消息: {msg.treated_msg}")
@bot.on_group_message
async def handle_group(msg: Model.GroupMessage):
await msg.reply(f"群聊消息: {msg.treated_msg}")
@bot.on_c2c_message
async def handle_c2c(msg: Model.C2CMessage):
await msg.reply(f"私信消息: {msg.treated_msg}")
bot.start()
亮点展示 — WaitFor 多轮对话 & 指令系统
from easybot import Bot, CommandValidScenes, Model, Scope
bot = Bot(app_id="你的AppID", app_secret="你的AppSecret")
# 指令系统:正则 + 管理员权限 + 短路机制,一行搞定
@bot.on_command(
regex=r"^查询 (.+)$",
is_require_admin=True,
valid_scenes=CommandValidScenes.GUILD,
)
async def query(msg: Model.GuildMessage):
await msg.reply(f"查询结果: {msg.treated_msg[0]}")
# 会话管理:WaitFor 等待用户回复,天然支持多轮对话
@bot.on_command(command=["签到"])
async def check_in(
msg: Model.GuildMessage | Model.GroupMessage | Model.C2CMessage | Model.DirectMessage,
) -> None:
with bot.session.bind(msg) as s:
await s.new(Scope.USER, "check_in", {"step": "confirm"})
await msg.reply("确认签到吗?(回复 yes/no)")
reply = await s.wait_for(scopes=Scope.USER, command=["yes", "no"], timeout=30)
if reply.content.strip() == "yes":
await msg.reply("✅ 签到成功!")
else:
await msg.reply("已取消签到。")
bot.start()
功能特性
消息类型支持
类型 |
说明 |
|---|---|
Message |
文本 / 图片 / 引用消息 |
MessageEmbed |
Embed 卡片消息 |
MessageArk23 |
Ark 23 链接模板 |
MessageArk24 |
Ark 24 图文模板 |
MessageArk37 |
Ark 37 大图模板 |
MessageMarkdown |
Markdown 消息 |
连接协议
协议 |
适用场景 |
|---|---|
WebSocket |
本地 / 服务器直连(默认) |
Webhook |
公网 IP / 云函数部署 |
Remote Webhook |
内网穿透 / 远程中转 |
核心能力一览
能力 |
说明 |
|---|---|
🤖 事件系统 |
40+ 事件装饰器,覆盖频道 / 群聊 / C2C / 私信 / 论坛 / 音频等全场景 |
💬 会话管理 |
Session 五级作用域 + WaitFor 异步等待,超时自动回复 + GC 回收 |
🎮 指令系统 |
关键词 / 正则匹配、管理员权限、短路机制、多场景隔离、预处理器 |
🧩 插件生态 |
自动扫描目录加载,支持装饰器注册方式 |
⏰ 生命周期 |
startup / shutdown / timer 三大内置事件 |
🔒 沙箱模式 |
一键开启沙箱环境,安全调试不干扰线上 |
文档
完整文档请参阅 docs 目录:
文档 |
内容 |
|---|---|
设计理念、核心价值、与其他方案对比 |
|
从安装到第一个机器人的完整指南 |
|
Bot / API / Protocol / Logger 等核心组件详解 |
|
完整 API 接口文档 |
|
消息构建器(Embed / Ark / Markdown 等) |
|
数据模型定义与字段说明 |
|
插件开发、指令系统、权限管理 |
|
会话 API 与 WaitFor 多轮对话详解 |
|
FAQ 与问题排查 |
|
问题提交与社区交流 |
环境要求
Python >= 3.10
aiohttp >= 3.9.0
pyyaml >= 6.0
获取机器人凭证
访问 QQ 开放平台 并登录
创建一个机器人应用
获取 AppID 和 AppSecret
许可证
本项目采用 MIT 许可证。
联系方式
作者:小念同学
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file easybot_qq-1.0.4.tar.gz.
File metadata
- Download URL: easybot_qq-1.0.4.tar.gz
- Upload date:
- Size: 114.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4289c0cc4afb8ceff881a6a3fdbb62ed0da854d45b9e6838911718fc21635da8
|
|
| MD5 |
f24ad94379ee0970ab5bfbcf4b0b42cd
|
|
| BLAKE2b-256 |
a192fe1ec940c08a3343e301648c52a9b9e65da78bec8c62969ef24dc8d35fe0
|
Provenance
The following attestation bundles were made for easybot_qq-1.0.4.tar.gz:
Publisher:
publish.yml on SaucePlum/easybot
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
easybot_qq-1.0.4.tar.gz -
Subject digest:
4289c0cc4afb8ceff881a6a3fdbb62ed0da854d45b9e6838911718fc21635da8 - Sigstore transparency entry: 1357221011
- Sigstore integration time:
-
Permalink:
SaucePlum/easybot@789344fdde3926501c1cc7ae3caf4f6c778eec8a -
Branch / Tag:
refs/tags/v1.0.4 - Owner: https://github.com/SaucePlum
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@789344fdde3926501c1cc7ae3caf4f6c778eec8a -
Trigger Event:
release
-
Statement type:
File details
Details for the file easybot_qq-1.0.4-py3-none-any.whl.
File metadata
- Download URL: easybot_qq-1.0.4-py3-none-any.whl
- Upload date:
- Size: 122.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5e5c0157f4fc9da927eff4bf36017f7e308efc2f3119550fe3cca0b6e243e01
|
|
| MD5 |
d0b00c5bd35d3fb9f829c8b74db94378
|
|
| BLAKE2b-256 |
020ed46a606fdae4971d9e96bd3a94a857aa06187846fd78b8a750846e4ee324
|
Provenance
The following attestation bundles were made for easybot_qq-1.0.4-py3-none-any.whl:
Publisher:
publish.yml on SaucePlum/easybot
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
easybot_qq-1.0.4-py3-none-any.whl -
Subject digest:
e5e5c0157f4fc9da927eff4bf36017f7e308efc2f3119550fe3cca0b6e243e01 - Sigstore transparency entry: 1357221022
- Sigstore integration time:
-
Permalink:
SaucePlum/easybot@789344fdde3926501c1cc7ae3caf4f6c778eec8a -
Branch / Tag:
refs/tags/v1.0.4 - Owner: https://github.com/SaucePlum
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@789344fdde3926501c1cc7ae3caf4f6c778eec8a -
Trigger Event:
release
-
Statement type: