python - 如何使用 discord.py 中的 id 获取频道?
问题描述
我有一个使用用户提供的参数发送嵌入的命令。其中一个论点是渠道。我已经将频道剥离到 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 中。谢谢!
解决方案
您指的是类本身,而不是实例。
channel = self.client.get_channel(embedConfig[0]) # Or `self.bot`, however you named it in __init__ method
推荐阅读
- c++ - 向网络浏览器提供名为“index.html”的默认网页
- c# - 如何将数据从 CSV 分配到对象
- python-3.x - 如何制作正号组和负号组的组
- java - 如何解决此错误:在模块中发现重复的类 com.google.android.gms.internal.vision.zzw
- javascript - 使用 swiperjs api 单击后如何等待 1 秒以移动另一个滑块?
- r - 对所有列应用乘法,但仅适用于具有正值的行
- javascript - TSX:数字输入的道具类型定义
- c# - 如何使用firesharp c#库(未知的确切子路径)从firebase检索数据?
- java - Google 驱动器 API 出现 500 内部服务器错误
- python - 处理日期时间