- 在 discord 适配中增加了一个函数 `translate`,用于将 `Alconna` 对象转为 discord 适配器中 `on_slash_command` 的创建结构
若原先的命令结构如下:
python
from nonebot.adapters.discord.api import (
IntegerOption,
NumberOption,
StringOption,
SubCommandOption,
UserOption,
)
from nonebot.adapters.discord.commands import on_slash_command
matcher = on_slash_command(
name="permission",
description="权限管理",
options=[
SubCommandOption(
name="add",
description="添加",
options=[
StringOption(
name="plugin",
description="插件名",
required=True,
),
IntegerOption(
name="priority",
description="优先级",
required=False,
),
],
),
SubCommandOption(
name="remove",
description="移除",
options=[
StringOption(name="plugin", description="插件名", required=True),
NumberOption(name="time", description="时长", required=False),
],
),
SubCommandOption(
name="ban",
description="禁用",
options=[
UserOption(name="user", description="用户", required=False),
],
),
],
)
则使用 `translate` 后可以改为:
python
from arclet.alconna import Args, Option, Alconna, CommandMeta
from nonebot_plugin_alconna.adapters.discord import MentionUser, translate
matcher = translate(
Alconna(
"permission",
Option("add", Args["plugin插件名", str]["priority?优先级", int]),
Option("remove", Args["plugin插件名", str]["time?时长", float]),
Option("ban", Args["user?用户", MentionUser]),
meta=CommandMeta("权限管理"),
)
)
**Full Changelog**: https://github.com/nonebot/plugin-alconna/compare/v0.17.0...v0.18.0