简体   繁体   中英

How do I fetch a channel using the id in discord.py?

I have a command that sends an embed with user-provided arguments. One of the arguments is a channel. I've stripped the channel down to the ID but get_channel says it's missing 1 required positional argument: 'id' . Here's my current code:

  @commands.command(description='Send an embed message with Title, Colour, Footer and Field customization.')
  async def embed(self, ctx, *, args=None):
    if args == None:
      #code here
    else:
      embedConfig=args.split(" | ")
      if (len(embedConfig)-1) > 4:
        await ctx.send("Too many arguments!")
      else:
        embed=discord.Embed(title=embedConfig[1], description=embedConfig[3], color=int(embedConfig[2][1:],16))
        embed.set_footer(text=embedConfig[4])
        embed.timestamp = datetime.now()
        embedConfig[0] = embedConfig[0].lstrip("<#")
        print(embedConfig[0])
        embedConfig[0] = int(embedConfig[0].rstrip(">"))
        print(embedConfig[0])
        await ctx.send(embedConfig)
        channel = discord.Client.get_channel(embedConfig[0])
        await channel.send(embed=embed)

I'm using the commands extension with the discord.py-rewrite and the command above is in a cog. Thanks!

You're referring to the class itself, not to the instance.

channel = self.client.get_channel(embedConfig[0]) # Or `self.bot`, however you named it in __init__ method

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM