Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subcommands in Python Bot

How to create sub commands in python bot.

   @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)
like image 838
Demotry Avatar asked Mar 07 '23 03:03

Demotry


1 Answers

You need to make Second a group too.

@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)
like image 70
Patrick Haugh Avatar answered Mar 15 '23 05:03

Patrick Haugh