mirror of
				https://github.com/nonebot/nonebot2.git
				synced 2025-10-30 22:46:40 +00:00 
			
		
		
		
	📝 add create matcher doc
This commit is contained in:
		| @@ -99,6 +99,38 @@ async def handle(matcher: Matcher): | ||||
| - `temp` 属性:配置事件响应器在下一次响应之后移除。 | ||||
| - `expire_time` 属性:配置事件响应器在指定时间之后移除。 | ||||
|  | ||||
| ## 创建事件响应器 | ||||
|  | ||||
| 在前面的介绍中,我们已经了解了事件响应器的组成,接下来我们就可以使用 `nonebot.plugin` 模块中定义的辅助函数来创建事件响应器。 | ||||
|  | ||||
| ```python {3} | ||||
| from nonebot import on_message | ||||
|  | ||||
| matcher = on_message() | ||||
| ``` | ||||
|  | ||||
| 用于定义事件响应器的辅助函数已经在 `nonebot` 主模块中被 `re-export` ,所以直接从 `nonebot` 导入即可。 | ||||
|  | ||||
| 辅助函数有以下几种: | ||||
|  | ||||
| 1. `on`: 创建任何类型的事件响应器。 | ||||
| 2. `on_metaevent`: 创建元事件响应器。 | ||||
| 3. `on_message`: 创建消息事件响应器。 | ||||
| 4. `on_request`: 创建请求事件响应器。 | ||||
| 5. `on_notice`: 创建通知事件响应器。 | ||||
| 6. `on_startswith`: 创建消息开头匹配事件响应器。 | ||||
| 7. `on_endswith`: 创建消息结尾匹配事件响应器。 | ||||
| 8. `on_keyword`: 创建消息关键词匹配事件响应器。 | ||||
| 9. `on_command`: 创建命令消息事件响应器。 | ||||
| 10. `on_shell_command`: 创建 shell 命令消息事件响应器。 | ||||
| 11. `on_regex`: 创建正则表达式匹配事件响应器。 | ||||
| 12. `CommandGroup`: 创建具有共同命令名称前缀的命令组。 | ||||
| 13. `MatcherGroup`: 创建具有共同参数的响应器组。 | ||||
|  | ||||
| 其中,`on_metaevent` `on_message` `on_request` `on_notice` 函数都是在 `on` 的基础上添加了对应的事件类型 `type`;`on_startswith` `on_endswith` `on_keyword` `on_command` `on_shell_command` `on_regex` 函数都是在 `on_message` 的基础上添加了对应的匹配规则 `rule`。 | ||||
|  | ||||
| ## 自定义规则 | ||||
|  | ||||
| <!-- TODO --> | ||||
|  | ||||
| ## 自定义权限 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user