0

Say I have the following command and subcommands:

@commands.group()
async def channel(self, ctx, channel_name_or_id):
    # convert channel_name_or_id to channel object

@channel.command()
async def get_mention(ctx, channel_object):
    await ctx.send(channel_object.mention)

@channel.command()
async def get_id(ctx, channel_object):
    await ctx.send(channel_object.id)

I want the parent command to convert the name or id to an object, and then pass that object to the subcommands. Is there a way to do this? Something like ctx.invoked_subcommand.pass(channel_object)?

CircuitSacul
  • 1,594
  • 12
  • 32

1 Answers1

0

You can get the channel object by using self.client.get_channel(id). You could use a class level variable that you instantiate in the __init__() (if it's a cog) and set that to the channel object.

Kelo
  • 1,783
  • 2
  • 9
  • 21
  • That's not a bad idea... My only concern is that won't it conflict if the same command is called twice at the same time? – CircuitSacul Jun 19 '20 at 19:42