首页 > 解决方案 > discord.py 无法从本地文件嵌入图像

问题描述

我使用此代码嵌入图像,它不会引发任何错误并且它发送嵌入但嵌入中没有任何内容。

e=discord.Embed()
file = discord.File("OWO.jpg", filename="OWO.jpg")
e.set_thumbnail(url="attachment://OWO.jpg")
msg = ctx.send(embed=e)

这是我嵌入图像的样子,里面什么都没有。

标签: discorddiscord.py

解决方案


如何将本地图像文件用于嵌入图像?

Discord 特殊情况上传图像附件并在嵌入中使用它,这样它就不会单独显示,而是在嵌入的缩略图、图像、页脚或作者图标中显示。

为此,请使用 abc.Messageable.send() 正常上传图像,并将嵌入的图像 URL 设置为 attachment://image.png,其中 image.png 是您将发送的图像的文件名。

快速示例:

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

注意:由于 Discord 的限制,文件名可能不包含下划线。

是否存在创建审核日志条目的事件?

文档:https ://discordpy.readthedocs.io/en/latest/faq.html#how-do-i-use-a-local-image-file-for-an-embed-image


推荐阅读