Skip to main content

强制 discord.py 命令框架对应于斜线。

项目描述

派皮 PyPI - Python 版本 PyPI - 下载 PyPI - 许可证 不和谐 给我买杯咖啡

不和谐-ext-fslash

该库还通过执行猴子补丁将来自 discord.py 命令框架的命令注册为 discord.py 中的斜线命令。

警告
同样,这个库的工作方式是一个猴子补丁,并非没有意外行为的可能性。

特征

它同时支持命令框架的冷却和其他装饰describe器以及应用命令的装饰器工作。
转换器将自动替换为Transformer斜线版本。
它还可以str通过接受来自命令参数的子命令来自动将无效注释转换为并注册过度嵌套的组命令。
即使您有太多命令并达到可注册斜杠命令的最大数量,我们也有办法处理它。(下面是一个示例)
如果您打算创建一个机器人,我们建议使用 HybridCommand,它是 discord.py 中的标准配置。

安装

$ pip install discord-ext-fslash

例子

普通的

以下是创建一个名为的命令的示例,该命令ping适用于斜杠和消息命令。

from discord.ext.fslash import extend_force_slash

...

bot = extend_force_slash(commands.Bot(command_prefix="fs!", intents=intents))

@bot.command()
async def ping(ctx):
    await ctx.reply("pong")

按类别拆分命令

即使命令框架中有太多命令需要在斜线中注册,它也提供了一种方法来实现它们,只需在组命令的斜线子命令中创建命令即可。
以下示例创建组命令server-tool并将entertainment命令框架​​中的命令设置为这些命令的子命令。

from discord.ext.fslash import extend_force_slash

...

bot = extend_force_slash(
    commands.Bot(command_prefix="fs!", intents=intents),
    first_groups=(
        discord.app_commands.Group(name="server-tool"),
        discord.app_commands.Group(name="entertainment")
    )
)

@bot.command(description="Ban member", fsparent="server-tool")
@commands.has_guild_permissions(ban_members=True)
@commands.bot_has_guild_permissions(ban_members=True)
@commands.cooldown(1, 10, commands.BucketType.guild)
@discord.app_commands.describe(member="Member to be banned")
async def ban(ctx, *, member: discord.Member):
    # `/server-tool ban member: ...` or `fs!ban ...` to run this command.
    await ctx.typing()
    await member.ban()
    await ctx.reply("pong")

@bot.command(description="Make wow", fsparent="entertainment")
async def wow(ctx):
    # `/entertainment wow` or `fs!wow` to run this command.
    await ctx.reply("wow")

文档

有一些功能可以提高兼容性以提供更大的便利。
有关详细信息,请参阅文档

贡献

问题和 PullRequest 的内容应该简短。
代码的风格应该与当前代码相似。
如果可能,请将所有文本限制为每行 100 个字符,注释除外。
对于评论,请尽可能每行限制为 200 个字符。

执照

麻省理工学院

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

discord-ext-fslash-0.1.26.tar.gz (13.9 kB 查看哈希

已上传 source

内置分布

discord_ext_fslash-0.1.26-py3-none-any.whl (13.4 kB 查看哈希

已上传 py3