簡體   English   中英

如何在 discord.py 中發送帶有一張圖片的 discord 嵌入?

[英]How to send a discord embed with one image in discord.py?

我不只是發送圖像,而是希望我的 discord 機器人使用 Discord 嵌入並附加圖像,但是,當嘗試使用 set_image 並將新嵌入發送到 discord 時,沒有提供 output。 我的項目目錄中有一個名為 output.png 的文件,我只是想看看是否可以在嵌入中使用它。 這是我使用的一些測試代碼:

@client.command(name='test')
async def test(ctx):
    embed = discord.Embed(title='test',colour=discord.Colour.dark_orange())
    embed.set_image('output.png')
    await ctx.send(embed=embed,file='output.png')

為什么這不會在 discord 上生成嵌入?

embed.set_image方法只接受一個 URL 的圖片,而send方法的file kwarg 需要是一個File object,所以如果你想發送本地保存的圖片,你需要將它作為一個文件連同嵌入,然后使用attachment://image.png URL; image.png可以更改。

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

查看常見問題解答

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM