Reputation: 1830
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)
?
Upvotes: 0
Views: 451
Reputation: 1893
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.
Upvotes: 0