首页 > 解决方案 > 仅触发嵌套组中的一个命令

问题描述

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

@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”,它就会出现,或者我可以以某种方式输入参数或者让它只做其中一个的东西?任何人都可以帮忙吗?

标签: pythondiscord.py

解决方案


invoke_without_subcommand=True在组装饰器中使用

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


推荐阅读