【发布时间】:2021-04-16 23:59:52
【问题描述】:
我有一个命令组,在一个 cog 中,称为“todo”,当它被自己调用时(即没有子命令),它会显示一个待办事项列表。如果子命令不存在,那么它会显示一条消息(因为否则,它只会显示待办事项列表)。问题在于后者,我无法让 if 语句工作。
@commands.group()
async def todo(self, ctx):
# Main todo command with subcommands, shows list
if self.bot.get_command(f"todo {ctx.invoked_subcommand}") == None:
# the API has said that it returns None if subcommand is not found
await ctx.send("Sorry, the `c!todo` command doesn't have that option.")
elif ctx.invoked_subcommand is None:
# code that shows list
使用此代码,即使我键入现有子命令或不键入子命令,它也会发送消息。
【问题讨论】:
标签: python python-3.x discord discord.py discord.py-rewrite