【问题标题】:How to use multi-word aliases in discord.py如何在 discord.py 中使用多词别名
【发布时间】:2021-10-21 15:07:00
【问题描述】:

我有一个要使用别名的命令,但别名包含 2 个单词。当我尝试使用别名时,不会触发该命令。有没有办法让我使用多个单词的别名?

命令代码:

@bot.command(aliases=["gn", "night night"]) #
async def goodnight(ctx):
    channel = ctx.channel
    await channel.send("@everyone Goodnight everyone!")

提前感谢您的帮助!

【问题讨论】:

    标签: python discord discord.py command


    【解决方案1】:

    您可以通过使用子命令创建命令组来创建带有空格的命令,例如

    @bot.group(aliases=["gn", "night"], invoke_without_command=True)
    async def goodnight(ctx):
        await ctx.send("@everyone Goodnight everyone!")
    
    @goodnight.command()
    async def night(ctx):
        await ctx.send("@everyone Goodnight everyone!")
    

    有关invoke_without_command here 和下面的cmets 的更多详细信息。

    我查看了 discord.py discord 服务器中的讨论,但没有发现其他在命令中包含空格的方法。

    【讨论】:

    • invoke_without_command=True 使goodnight 命令仅在未调用night 子命令时才被调用。如果invoke_without_command 设置为False(或省略)并且用户使用night night 命令,则消息“大家晚安!”会出现两次。更多细节在这里:discordpy.readthedocs.io/en/latest/ext/commands/…
    猜你喜欢
    • 2020-11-13
    • 2019-04-26
    • 1970-01-01
    • 2019-09-04
    • 2023-01-28
    • 1970-01-01
    • 2020-10-12
    • 2021-04-25
    • 2019-04-30
    相关资源
    最近更新 更多