2021-03-20 15:41:50 +08:00
|
|
|
---
|
|
|
|
contentSidebar: true
|
|
|
|
sidebarDepth: 0
|
|
|
|
---
|
|
|
|
|
|
|
|
# NoneBot.handler 模块
|
|
|
|
|
|
|
|
## 事件处理函数
|
|
|
|
|
|
|
|
该模块实现事件处理函数的封装,以实现动态参数等功能。
|
|
|
|
|
|
|
|
|
|
|
|
## _class_ `Handler`
|
|
|
|
|
|
|
|
基类:`object`
|
|
|
|
|
2021-11-17 20:38:35 +08:00
|
|
|
事件处理器类。支持依赖注入。
|
2021-03-20 15:41:50 +08:00
|
|
|
|
|
|
|
|
2021-11-21 16:13:56 +08:00
|
|
|
### `__init__(func, *, name=None, dependencies=None, allow_types=None)`
|
2021-03-20 15:41:50 +08:00
|
|
|
|
|
|
|
|
2021-11-17 20:38:35 +08:00
|
|
|
* **说明**
|
2021-03-20 15:41:50 +08:00
|
|
|
|
2021-11-17 20:38:35 +08:00
|
|
|
装饰一个函数为事件处理器。
|
2021-03-20 15:41:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-11-17 20:38:35 +08:00
|
|
|
* **参数**
|
2021-03-20 15:41:50 +08:00
|
|
|
|
2021-11-17 20:38:35 +08:00
|
|
|
|
2021-11-19 18:20:20 +08:00
|
|
|
* `func: Callable[..., Any]`: 事件处理函数。
|
2021-03-20 15:41:50 +08:00
|
|
|
|
|
|
|
|
2021-11-17 20:38:35 +08:00
|
|
|
* `name: Optional[str]`: 事件处理器名称。默认为函数名。
|
2021-03-20 15:41:50 +08:00
|
|
|
|
|
|
|
|
2021-11-17 20:38:35 +08:00
|
|
|
* `dependencies: Optional[List[DependsWrapper]]`: 额外的非参数依赖注入。
|
2021-03-20 15:41:50 +08:00
|
|
|
|
|
|
|
|
2021-11-17 20:38:35 +08:00
|
|
|
* `allow_types: Optional[List[Type[Param]]]`: 允许的参数类型。
|
2021-03-20 15:41:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-11-17 20:38:35 +08:00
|
|
|
### `func`
|
2021-03-20 15:41:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
* **类型**
|
|
|
|
|
2021-11-19 18:20:20 +08:00
|
|
|
`Callable[..., Any]`
|
2021-03-20 15:41:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **说明**
|
|
|
|
|
2021-11-17 20:38:35 +08:00
|
|
|
事件处理函数
|
2021-03-20 15:41:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-11-17 20:38:35 +08:00
|
|
|
### `name`
|
2021-03-20 15:41:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
* **类型**
|
|
|
|
|
2021-11-17 20:38:35 +08:00
|
|
|
`str`
|
2021-03-20 15:41:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **说明**
|
|
|
|
|
2021-11-17 20:38:35 +08:00
|
|
|
事件处理函数名
|
2021-03-20 15:41:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-11-17 20:38:35 +08:00
|
|
|
### `allow_types`
|
2021-03-20 15:41:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
* **类型**
|
|
|
|
|
2021-11-17 20:38:35 +08:00
|
|
|
`List[Type[Param]]`
|
2021-03-20 15:41:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **说明**
|
|
|
|
|
2021-11-17 20:38:35 +08:00
|
|
|
事件处理器允许的参数类型
|
2021-03-20 15:41:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-11-17 20:38:35 +08:00
|
|
|
### `dependencies`
|
2021-03-20 15:41:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
* **类型**
|
|
|
|
|
2021-11-17 20:38:35 +08:00
|
|
|
`List[DependsWrapper]`
|
2021-03-20 15:41:50 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
* **说明**
|
|
|
|
|
2021-11-17 20:38:35 +08:00
|
|
|
事件处理器的额外依赖
|