python - 仅触发嵌套组中的一个命令
问题描述
所以我正在编写一个不和谐的机器人,我的朋友告诉我我可以把一个组放在另一个组中,所以我试了一下:
@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”,它就会出现,或者我可以以某种方式输入参数或者让它只做其中一个的东西?任何人都可以帮忙吗?
解决方案
invoke_without_subcommand=True
在组装饰器中使用
@bot.group(aliases=['dono'], invoke_without_subcommand=True)
推荐阅读
- c# - c# Populate datagridview based on ComboBox Item Selected
- database - 如何从 PL/SQL 中的触发器回滚列
- python-3.x - 从虚拟环境运行 heroku django 应用程序
- python - 300k 请求后连接中止,RemoteDisconnected('远程结束关闭连接没有响应')
- c# - 使用 c# 在 Switch 案例中设置 IOS 权限
- android - 'hardwareBackPress' 侦听器未在反应原生 android 中的“模糊”事件中删除
- apache-kafka - kafka-consumer-perf-test.sh 为 --message 参数的不同值显示不同的 nMsg.sec
- c# - 如何配置 IIS 以使用 MS PowerPoint 运行 Asp.Net Core 应用程序
- c# - 如何使用 Quartz.net 仅使用一个触发器来安排多个作业
- apache-spark - Why Spark Streaming ExecutorAllocationManager do not need to enable ExternalShuffleService