【问题标题】:Discord.py | Image not sending不和谐.py |图片未发送
【发布时间】:2020-09-10 23:26:37
【问题描述】:

我正在为我的 discord 机器人制作一个 nsfw cmd。 概括: 从文件夹中选择随机文件,然后将其附加到嵌入并发送。

这是我的代码:

fp = random.choice(os.listdir('NSFW/Ass/'))
await ctx.send(file = discord.File('NSFW/Ass/%s' % (fp)), embed = discord.Embed(title = None, description = None, colour = 0xaa00ff))

它输出这个: https://jokers.has-no-bra.in/oEVtd1 我希望它输出: 像这样的东西:https://jokers.has-no-bra.in/NxSkKF

【问题讨论】:

  • 我试过这个,embed.set_image(url = 'attachment://NSFW/Ass/%s.png' % (fp)) 但它输出一个没有图像的嵌入

标签: python discord discord.py


【解决方案1】:

链接图片时,需要给它起个名字(image.png 就可以了,不一定是文件的真实名称),然后引用它为attachment://name

embed = discord.Embed()
file = discord.File(path_to_your_file, filename="image.png")
embed.set_image(url="attachment://image.png")
await ctx.send(embed=embed, file=file)

【讨论】:

    【解决方案2】:
    @bot.command()
    async def test(ctx):
        fp = random.choice(os.listdir('NSFW'))
        file = discord.File(f"NSFW/{fp}", filename="image.png")
    
        e = discord.Embed()
        e.set_image(url="attachment://image.png")
        await ctx.send(embed=e, file=file)
    

    注意,File 构造函数中的文件名和 URL 中的文件名必须匹配。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-06-28
      • 2022-01-18
      • 2021-01-19
      • 2019-01-29
      • 2021-11-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多