说我有以下命令和子命令:
@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)
我希望父命令将名称或id转换为对象,然后然后将该对象传递给子命令。有没有办法做到这一点?像ctx.invoked_subcommand.pass(channel_object)
之类的东西?
答案 0 :(得分:0)
您可以使用self.client.get_channel(id)
获取频道对象。您可以使用在__init__()
中实例化的类级变量(如果是齿轮)并将其设置为通道对象。