Python 使用文件在discord.py中嵌入附件时出现问题
这是我使用的代码:Python 使用文件在discord.py中嵌入附件时出现问题,python,python-3.x,discord.py,Python,Python 3.x,Discord.py,这是我使用的代码: if message.attachments: file = await message.attachments[0].to_file() file.filename = 'image.png' embed.set_image(url='attachment://image.png') for x in my_channels: webhook = Webhook.from
if message.attachments:
file = await message.attachments[0].to_file()
file.filename = 'image.png'
embed.set_image(url='attachment://image.png')
for x in my_channels:
webhook = Webhook.from_url(x, adapter=AsyncWebhookAdapter(session))
await webhook.send(file=file, embed=embed)
它使用webhook将嵌入发送到3个通道(尝试了正常的方式,但仍然不起作用),图像只发送到一个通道,其他通道没有图像字段。没有任何错误,但我认为该文件在某种程度上是“不可重用的”,因为我需要单独发送它,所以它不在保存的文件中。有什么解决办法吗?来自
文件对象是一次性的,不能在多个abc.Messageable.send()中重复使用
解决问题的一种方法是在for循环中重新定义文件
如果message.attachments:
嵌入.set_图像(url='attachment://image.png')
对于my_频道中的x:
file=等待消息。附件[0]。到_文件()
file.filename='image.png'
webhook=webhook.from_url(x,adapter=AsyncWebhookAdapter(会话))
等待webhook.send(file=file,embed=embed)
就可以了,谢谢!