mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-07-27 16:21:28 +00:00
Update docs
This commit is contained in:
@ -12,11 +12,12 @@ await bot.send_private_msg(user_id=12345678, message='你好~')
|
||||
|
||||
这里,`send_private_msg` 实际上对应 CQHTTP 的 [`/send_private_msg` 接口](https://cqhttp.cc/docs/#/API?id=send_private_msg-%E5%8F%91%E9%80%81%E7%A7%81%E8%81%8A%E6%B6%88%E6%81%AF),其它接口同理。
|
||||
|
||||
通过这种方式调用 API 时,需要注意两点:
|
||||
通过这种方式调用 API 时,需要注意下面几点:
|
||||
|
||||
1. **所有参数必须为命名参数(keyword argument)**,否则无法正确调用
|
||||
2. 这种调用全都是异步调用,因此需要适当 `await`
|
||||
2. **调用失败时(没有权限、对方不是好友、无 API 连接等)可能抛出 `nonebot.CQHttpError` 异常**,注意捕获
|
||||
2. 这种调用**全都是异步调用**,因此需要适当 `await`
|
||||
3. **调用失败时(没有权限、对方不是好友、无 API 连接等)可能抛出 `nonebot.CQHttpError` 异常**,注意捕获
|
||||
4. **当多个机器人使用同一个 NoneBot 后端时**,可能需要加上参数 `self_id=<机器人QQ号>`,例如 `await bot.get_group_list(self_id=session.ctx['self_id'])`
|
||||
|
||||
另外,在需要动态性的场合,除了使用 `getattr()` 方法外,还可以直接调用 `bot.call_action()` 方法,传入 `action` 和 `params` 即可,例如上例中,`action` 为 `'send_private_msg'`,`params` 为 `{'user_id': 12345678, 'message': '你好~'}`。
|
||||
|
||||
|
Reference in New Issue
Block a user