首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用discord.py中的id获取频道?

如何使用discord.py中的id获取频道?
EN

Stack Overflow用户
提问于 2021-02-23 17:14:11
回答 1查看 250关注 0票数 0

我有一个命令,它发送一个带有用户提供的参数的embed。其中一个参数是通道。我已经把频道缩小到ID了,但是get_channel说是missing 1 required positional argument: 'id'。下面是我当前的代码:

代码语言:javascript
复制
  @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的命令扩展,上面的命令在一个齿轮中。谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-23 17:19:36

您引用的是类本身,而不是实例。

代码语言:javascript
复制
channel = self.client.get_channel(embedConfig[0]) # Or `self.bot`, however you named it in __init__ method
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66330208

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档