gpt4 book ai didi

python - Python Bot 中的子命令

转载 作者:行者123 更新时间:2023-12-01 01:53:00 26 4
gpt4 key购买 nike

如何在 python 机器人中创建子命令。

   @bot.group(pass_context=True)
async def First(ctx):
if ctx.invoked_subcommand is None:
await bot.say('Invalid sub command passed...')

@First.command(pass_context=True)
async def Second(ctx):
msg = 'Finally got success {0.author.mention}'.format(ctx.message)
await bot.say(msg)

最佳答案

您也需要将Second 设为一个组。

@bot.group(pass_context=True)
async def First(ctx):
if ctx.invoked_subcommand is None:
await bot.say('Invalid sub command passed...')

@First.group(pass_context=True)
async def Second(ctx):
if ctx.invoked_subcommand is Second:
await bot.say('Invalid sub command passed...')

@Second.command(pass_context=True)
async def Third(ctx):
msg = 'Finally got success {0.author.mention}'.format(ctx.message)
await bot.say(msg)

关于python - Python Bot 中的子命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50548316/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com