A very common reason is a wrong site baseUrl configuration.\n Current configured baseUrl = / (default value)\n We suggest trying baseUrl = \n\n',document.body.prepend(n);var e=document.getElementById("__docusaurus-base-url-issue-banner-suggestion-container"),s=window.location.pathname;e.textContent="/"===s.substr(-1)?s:s+"/"} Skip to main contentNoneBot2.5.0Next2.5.02.4.42.4.31.x搜索指南快速上手尝试使用 NoneBot手动创建项目创建一个 NoneBot 项目机器人的构成NoneBot 机器人构成及基本使用获取商店内容从商店安装适配器和插件插件编写准备创建并加载自定义插件事件响应器响应接收到的特定事件事件处理处理接收到的特定事件获取事件信息通过依赖注入获取所需事件信息处理消息处理消息序列与消息段2.5.0StableDocumentation for the latest, stable, branch.NextDevelopmentDocumentation for the latest, in-development, branch.深入配置读取用户配置来控制插件行为响应规则自定义响应规则会话控制更灵活的会话控制会话状态会话状态信息使用平台接口使用平台接口,完成更多功能权限控制控制事件响应器的权限日志记录与控制日志事件类型与重载根据事件类型进行不同的处理2.5.0StableDocumentation for the latest, stable, branch.NextDevelopmentDocumentation for the latest, in-development, branch.进阶选择驱动器选择合适的驱动器运行机器人使用适配器注册适配器与指定平台交互插件信息填写与获取插件相关的信息嵌套插件编写与加载嵌套插件跨插件访问使用其他插件提供的功能事件响应器进阶事件响应器组成与内置响应规则依赖注入通过依赖注入获取上下文信息会话更新控制会话响应对象钩子函数在特定的生命周期中执行代码添加路由添加服务端路由规则事件响应器存储自定义事件响应器存储2.5.0StableDocumentation for the latest, stable, branch.NextDevelopmentDocumentation for the latest, in-development, branch.API更多最佳实践开发者社区开源之夏商店更新日志论坛ThemeNoneBot指南深入进阶API更多ThemecloseNoneBot跨平台 Python 异步机器人框架开始使用 $ pipx run nb-cli createout of box开箱即用使用 NB-CLI 快速构建属于你的机器人Installation$ pipx install nb-cli$ nb[?] What do you want to do?❯ Create a NoneBot project. Run the bot in current folder. Manage bot driver. Manage bot adapters. Manage bot plugins. ...plugin system插件系统插件化开发,模块化管理import nonebot# 加载一个插件nonebot.load_plugin("path.to.your.plugin")# 从文件夹加载插件nonebot.load_plugins("plugins")# 从配置文件加载多个插件nonebot.load_from_json("plugins.json")nonebot.load_from_toml("pyproject.toml")cross-platform support跨平台支持支持多种平台,以及多样的事件响应方式import nonebot# OneBotfrom nonebot.adapters.onebot.v11 import Adapter as OneBotAdapter# QQ 机器人from nonebot.adapters.qq import Adapter as QQAdapterdriver = nonebot.get_driver()driver.register_adapter(OneBotAdapter)driver.register_adapter(QQAdapter)asynchronous first异步开发异步优先式开发,提高运行效率from nonebot import on_message# 注册一个消息响应器matcher = on_message()# 注册一个消息处理器# 并重复收到的消息@matcher.handle()async def handler(event: Event) -> None: await matcher.send(event.get_message())builtin dependency injection system依赖注入简单清晰的依赖注入系统,内置依赖函数减少用户代码from nonebot import on_command# 注册一个命令响应器matcher = on_command("help", alias={"帮助"})# 注册一个命令处理器# 通过依赖注入获得命令名以及参数@matcher.handle()async def handler(cmd = Command(), arg = CommandArg()) -> None: await matcher.finish()
Current configured baseUrl = / (default value)\n We suggest trying baseUrl = \n\n',document.body.prepend(n);var e=document.getElementById("__docusaurus-base-url-issue-banner-suggestion-container"),s=window.location.pathname;e.textContent="/"===s.substr(-1)?s:s+"/"} Skip to main contentNoneBot2.5.0Next2.5.02.4.42.4.31.x搜索指南快速上手尝试使用 NoneBot手动创建项目创建一个 NoneBot 项目机器人的构成NoneBot 机器人构成及基本使用获取商店内容从商店安装适配器和插件插件编写准备创建并加载自定义插件事件响应器响应接收到的特定事件事件处理处理接收到的特定事件获取事件信息通过依赖注入获取所需事件信息处理消息处理消息序列与消息段2.5.0StableDocumentation for the latest, stable, branch.NextDevelopmentDocumentation for the latest, in-development, branch.深入配置读取用户配置来控制插件行为响应规则自定义响应规则会话控制更灵活的会话控制会话状态会话状态信息使用平台接口使用平台接口,完成更多功能权限控制控制事件响应器的权限日志记录与控制日志事件类型与重载根据事件类型进行不同的处理2.5.0StableDocumentation for the latest, stable, branch.NextDevelopmentDocumentation for the latest, in-development, branch.进阶选择驱动器选择合适的驱动器运行机器人使用适配器注册适配器与指定平台交互插件信息填写与获取插件相关的信息嵌套插件编写与加载嵌套插件跨插件访问使用其他插件提供的功能事件响应器进阶事件响应器组成与内置响应规则依赖注入通过依赖注入获取上下文信息会话更新控制会话响应对象钩子函数在特定的生命周期中执行代码添加路由添加服务端路由规则事件响应器存储自定义事件响应器存储2.5.0StableDocumentation for the latest, stable, branch.NextDevelopmentDocumentation for the latest, in-development, branch.API更多最佳实践开发者社区开源之夏商店更新日志论坛ThemeNoneBot指南深入进阶API更多ThemecloseNoneBot跨平台 Python 异步机器人框架开始使用 $ pipx run nb-cli createout of box开箱即用使用 NB-CLI 快速构建属于你的机器人Installation$ pipx install nb-cli$ nb[?] What do you want to do?❯ Create a NoneBot project. Run the bot in current folder. Manage bot driver. Manage bot adapters. Manage bot plugins. ...plugin system插件系统插件化开发,模块化管理import nonebot# 加载一个插件nonebot.load_plugin("path.to.your.plugin")# 从文件夹加载插件nonebot.load_plugins("plugins")# 从配置文件加载多个插件nonebot.load_from_json("plugins.json")nonebot.load_from_toml("pyproject.toml")cross-platform support跨平台支持支持多种平台,以及多样的事件响应方式import nonebot# OneBotfrom nonebot.adapters.onebot.v11 import Adapter as OneBotAdapter# QQ 机器人from nonebot.adapters.qq import Adapter as QQAdapterdriver = nonebot.get_driver()driver.register_adapter(OneBotAdapter)driver.register_adapter(QQAdapter)asynchronous first异步开发异步优先式开发,提高运行效率from nonebot import on_message# 注册一个消息响应器matcher = on_message()# 注册一个消息处理器# 并重复收到的消息@matcher.handle()async def handler(event: Event) -> None: await matcher.send(event.get_message())builtin dependency injection system依赖注入简单清晰的依赖注入系统,内置依赖函数减少用户代码from nonebot import on_command# 注册一个命令响应器matcher = on_command("help", alias={"帮助"})# 注册一个命令处理器# 通过依赖注入获得命令名以及参数@matcher.handle()async def handler(cmd = Command(), arg = CommandArg()) -> None: await matcher.finish()
We suggest trying baseUrl = \n\n',document.body.prepend(n);var e=document.getElementById("__docusaurus-base-url-issue-banner-suggestion-container"),s=window.location.pathname;e.textContent="/"===s.substr(-1)?s:s+"/"} Skip to main contentNoneBot2.5.0Next2.5.02.4.42.4.31.x搜索指南快速上手尝试使用 NoneBot手动创建项目创建一个 NoneBot 项目机器人的构成NoneBot 机器人构成及基本使用获取商店内容从商店安装适配器和插件插件编写准备创建并加载自定义插件事件响应器响应接收到的特定事件事件处理处理接收到的特定事件获取事件信息通过依赖注入获取所需事件信息处理消息处理消息序列与消息段2.5.0StableDocumentation for the latest, stable, branch.NextDevelopmentDocumentation for the latest, in-development, branch.深入配置读取用户配置来控制插件行为响应规则自定义响应规则会话控制更灵活的会话控制会话状态会话状态信息使用平台接口使用平台接口,完成更多功能权限控制控制事件响应器的权限日志记录与控制日志事件类型与重载根据事件类型进行不同的处理2.5.0StableDocumentation for the latest, stable, branch.NextDevelopmentDocumentation for the latest, in-development, branch.进阶选择驱动器选择合适的驱动器运行机器人使用适配器注册适配器与指定平台交互插件信息填写与获取插件相关的信息嵌套插件编写与加载嵌套插件跨插件访问使用其他插件提供的功能事件响应器进阶事件响应器组成与内置响应规则依赖注入通过依赖注入获取上下文信息会话更新控制会话响应对象钩子函数在特定的生命周期中执行代码添加路由添加服务端路由规则事件响应器存储自定义事件响应器存储2.5.0StableDocumentation for the latest, stable, branch.NextDevelopmentDocumentation for the latest, in-development, branch.API更多最佳实践开发者社区开源之夏商店更新日志论坛ThemeNoneBot指南深入进阶API更多ThemecloseNoneBot跨平台 Python 异步机器人框架开始使用 $ pipx run nb-cli createout of box开箱即用使用 NB-CLI 快速构建属于你的机器人Installation$ pipx install nb-cli$ nb[?] What do you want to do?❯ Create a NoneBot project. Run the bot in current folder. Manage bot driver. Manage bot adapters. Manage bot plugins. ...plugin system插件系统插件化开发,模块化管理import nonebot# 加载一个插件nonebot.load_plugin("path.to.your.plugin")# 从文件夹加载插件nonebot.load_plugins("plugins")# 从配置文件加载多个插件nonebot.load_from_json("plugins.json")nonebot.load_from_toml("pyproject.toml")cross-platform support跨平台支持支持多种平台,以及多样的事件响应方式import nonebot# OneBotfrom nonebot.adapters.onebot.v11 import Adapter as OneBotAdapter# QQ 机器人from nonebot.adapters.qq import Adapter as QQAdapterdriver = nonebot.get_driver()driver.register_adapter(OneBotAdapter)driver.register_adapter(QQAdapter)asynchronous first异步开发异步优先式开发,提高运行效率from nonebot import on_message# 注册一个消息响应器matcher = on_message()# 注册一个消息处理器# 并重复收到的消息@matcher.handle()async def handler(event: Event) -> None: await matcher.send(event.get_message())builtin dependency injection system依赖注入简单清晰的依赖注入系统,内置依赖函数减少用户代码from nonebot import on_command# 注册一个命令响应器matcher = on_command("help", alias={"帮助"})# 注册一个命令处理器# 通过依赖注入获得命令名以及参数@matcher.handle()async def handler(cmd = Command(), arg = CommandArg()) -> None: await matcher.finish()
快速上手
尝试使用 NoneBot
手动创建项目
创建一个 NoneBot 项目
机器人的构成
NoneBot 机器人构成及基本使用
获取商店内容
从商店安装适配器和插件
插件编写准备
创建并加载自定义插件
事件响应器
响应接收到的特定事件
事件处理
处理接收到的特定事件
获取事件信息
通过依赖注入获取所需事件信息
处理消息
处理消息序列与消息段
配置
读取用户配置来控制插件行为
响应规则
自定义响应规则
会话控制
更灵活的会话控制
会话状态
会话状态信息
使用平台接口
使用平台接口,完成更多功能
权限控制
控制事件响应器的权限
日志
记录与控制日志
事件类型与重载
根据事件类型进行不同的处理
选择驱动器
选择合适的驱动器运行机器人
使用适配器
注册适配器与指定平台交互
插件信息
填写与获取插件相关的信息
嵌套插件
编写与加载嵌套插件
跨插件访问
使用其他插件提供的功能
事件响应器进阶
事件响应器组成与内置响应规则
依赖注入
通过依赖注入获取上下文信息
会话更新
控制会话响应对象
钩子函数
在特定的生命周期中执行代码
添加路由
添加服务端路由规则
事件响应器存储
自定义事件响应器存储
跨平台 Python 异步机器人框架
$ pipx run nb-cli create
out of box
使用 NB-CLI 快速构建属于你的机器人
$ pipx install nb-cli$ nb[?] What do you want to do?❯ Create a NoneBot project. Run the bot in current folder. Manage bot driver. Manage bot adapters. Manage bot plugins. ...
plugin system
插件化开发,模块化管理
import nonebot# 加载一个插件nonebot.load_plugin("path.to.your.plugin")# 从文件夹加载插件nonebot.load_plugins("plugins")# 从配置文件加载多个插件nonebot.load_from_json("plugins.json")nonebot.load_from_toml("pyproject.toml")
cross-platform support
支持多种平台,以及多样的事件响应方式
import nonebot# OneBotfrom nonebot.adapters.onebot.v11 import Adapter as OneBotAdapter# QQ 机器人from nonebot.adapters.qq import Adapter as QQAdapterdriver = nonebot.get_driver()driver.register_adapter(OneBotAdapter)driver.register_adapter(QQAdapter)
asynchronous first
异步优先式开发,提高运行效率
from nonebot import on_message# 注册一个消息响应器matcher = on_message()# 注册一个消息处理器# 并重复收到的消息@matcher.handle()async def handler(event: Event) -> None: await matcher.send(event.get_message())
builtin dependency injection system
简单清晰的依赖注入系统,内置依赖函数减少用户代码
from nonebot import on_command# 注册一个命令响应器matcher = on_command("help", alias={"帮助"})# 注册一个命令处理器# 通过依赖注入获得命令名以及参数@matcher.handle()async def handler(cmd = Command(), arg = CommandArg()) -> None: await matcher.finish()