discord-py-保存用户发布的图片并删除旧图片



我的bot应该从特定通道中的所有消息中进行嵌入。他删除了所有不在嵌入中的消息,并自动将它们放入嵌入中。现在,这是可行的,但我的用户上传的图片有问题。

我的问题:我如何将用户上传的图片保存在"日志通道";并从那张照片中获得新的discord图像链接?

我需要";新的不和谐图像链接";将其放入嵌入。

discord.Message实例包含attachments属性,该属性将为您提供消息附件的列表。然后,您可以使用discord.Attachment.to_file()来获得一个discord.File实例,该实例可以在嵌入中使用。

示例:

message = SomeMessageInstance
# realistically you should be looping over the attachments, and sending an embed for each
file = await message.attachments[0].to_file()
file.filename = 'image.png'
embed = discord.Embed()
embed.set_image(url='attachment://image.png')
await Channel.send(file=file, embed=embed)

最新更新