仅触发嵌套组中的一个命令

时间:2021-01-08 01:16:57

标签: python discord.py

所以我正在编写一个不和谐的机器人,我的朋友告诉我我可以把一个组放在另一个组中,所以我像这样试了一下:

@bot.group(aliases=['dono'])
async def donation(ctx):
    """Adds/subtracts to someone's total donation in a server (must be done by a mod)."""

@donation.group(aliases=['lb'])
async def leaderboard(ctx):
    """Shows the leaderboard for the users who donated the most."""
    [some long boring code that has no errors, that essentially just sends a leaderboard on who has donated the most]
        
@leaderboard.command(aliases=['gaw', 'ga'])
async def giveaway(ctx):
    """Shows the leaderboard for the users who donated the most to giveaways."""
    [some more perfectly fine but boring code that shows who has donated the most to giveaways]

但是,(假设我的前缀是 '!')当我执行“!dono lb gaw”时,它会同时运行排行榜和赠品排行榜命令。所以我想出了两个解决方案,但在网上找不到任何东西。一个是删除排行榜命令中的所有代码,然后以某种方式创建一个空命令,如果你只是输入'!dono lb',它就会显示出来,或者如果我能以某种方式输入参数或者让它只做其中一个?有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

在组装饰器中使用 invoke_without_subcommand=True

@bot.group(aliases=['dono'], invoke_without_subcommand=True)

相关问题