簡體   English   中英

如何使用 discord.py 中的 id 獲取頻道?

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

我有一個使用用戶提供的 arguments 發送嵌入的命令。 arguments 之一是通道。 我已將頻道剝離為 ID,但 get_channel 說它missing 1 required positional argument: 'id' 這是我當前的代碼:

  @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)

我正在使用帶有 discord.py-rewrite 的命令擴展名,上面的命令位於 cog 中。 謝謝!

您指的是 class 本身,而不是實例。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM