mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-07-28 08:41:29 +00:00
Add docs for writing "usage" command
This commit is contained in:
20
docs/guide/code/awesome-bot-7/awesome/plugins/usage.py
Normal file
20
docs/guide/code/awesome-bot-7/awesome/plugins/usage.py
Normal file
@ -0,0 +1,20 @@
|
||||
import nonebot
|
||||
from nonebot import on_command, CommandSession
|
||||
|
||||
|
||||
@on_command('usage', aliases=['使用帮助', '帮助', '使用方法'])
|
||||
async def _(session: CommandSession):
|
||||
# 获取设置了名称的插件列表
|
||||
plugins = list(filter(lambda p: p.name, nonebot.get_loaded_plugins()))
|
||||
|
||||
arg = session.current_arg_text.strip().lower()
|
||||
if not arg:
|
||||
# 如果用户没有发送参数,则发送功能列表
|
||||
await session.send(
|
||||
'我现在支持的功能有:\n\n' + '\n'.join(p.name for p in plugins))
|
||||
return
|
||||
|
||||
# 如果发了参数则发送相应命令的使用帮助
|
||||
for p in plugins:
|
||||
if p.name.lower() == arg:
|
||||
await session.send(p.usage)
|
Reference in New Issue
Block a user