【问题标题】:Discord.py reupload imageDiscord.py 重新上传图片
【发布时间】:2020-11-23 08:59:10
【问题描述】:

我使用的库是 discord.py 重写

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

当用户向#memes 发送图片时:

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

一段时间后,链接过期,它看起来像like this

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

【问题讨论】:

    标签: python python-3.x discord python-3.6 discord.py-rewrite


    【解决方案1】:

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

    @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

    【讨论】:

    • 看到bot.commandself 有点奇怪。这是在Cog 里面吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-08
    • 2020-10-20
    • 2013-09-11
    • 1970-01-01
    • 2020-07-25
    • 2020-08-09
    相关资源
    最近更新 更多