Discord.py 重新上传图片

Discord.py reupload image

The library I'm using is the discord.py rewrite

所以我在我的服务器上制作了一个模因功能,但我遇到了一个问题。问题出在我的算法上。

当用户将图像发送到#memes 时:

  1. 使用该附件的 link 创建并嵌入
  2. 发送嵌入
  3. 删除用户的消息

一段时间后,link 过期,看起来 like this。

我知道我必须做什么,但我不知道怎么做。 我需要机器人重新上传图像并获得 cdn.discordapp.com link.

这就是我让机器人重新上传嵌入图像的方式

@bot.command()
async def attach(self, ctx):
    f = await ctx.message.attachments[0].to_file()
    embed = discord.Embed()
    embed.set_image(url=f"attachment://{f.filename}")
    await channel.send(file=f, embed=embed)

https://discordpy.readthedocs.io/en/latest/api.html#discord.Attachment.to_file