From 9179e3ac4eebb6cea430a060e52aa512a22caf39 Mon Sep 17 00:00:00 2001 From: Richard Chien Date: Mon, 16 Mar 2020 21:09:26 +0800 Subject: [PATCH] update docs --- docs/api.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/docs/api.md b/docs/api.md index 42a96f88..e502b3dd 100644 --- a/docs/api.md +++ b/docs/api.md @@ -676,6 +676,41 @@ sidebar: auto 在 `127.0.0.1:8080` 运行全局 NoneBot 对象。 +### _decorator_ `on_startup` + +- **说明:** + + 将函数装饰为 NoneBot 启动时的回调函数。 + +- **用法:** + + ```python + @on_startup + async def startup() + await db.init() + ``` + + 注册启动时回调,初始化数据库。 + +### _decorator_ `on_websocket_connect` + +- **说明:** + + 将函数装饰为 CQHTTP 反向 WebSocket 连接建立时的回调函数。 + + 该装饰器等价于 `@bot.on_meta_event('lifecycle.connect')`,只在 CQHTTP v4.14+ 有用。 + +- **用法:** + + ```python + @on_websocket_connect + async def connect(event: aiocqhttp.Event): + bot = nonebot.get_bot() + groups = await bot.get_group_list() + ``` + + 注册 WebSocket 连接时回调,获取群列表。 + ## `nonebot.exceptions` 模块 ### _class_ `CQHttpError`