You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用discord_webhook库时嵌入消息无法包含图片问题求助

解决Discord Webhook嵌入消息与图片分离的问题

问题出在你仅将图片添加为Webhook的附件,但未在嵌入消息中关联该图片。Discord的嵌入消息需要明确引用上传的附件,才能将图片显示在嵌入内,而非作为独立附件发送。

修正步骤:

  • 在添加文件后,使用embed.set_image()方法,将图片URL指定为attachment://文件名格式(Discord会自动解析上传的附件为该路径)。

修正后的代码:

webhook = DiscordWebhook(url=webhook_url, username="Test")

embed = DiscordEmbed()
embed.set_title("Test")
# 添加图片文件到Webhook
with open("Image.png", "rb") as f:
    webhook.add_file(file=f.read(), filename="Image.png")
# 在嵌入中关联该图片
embed.set_image(url="attachment://Image.png")
embed.add_embed_field(name="Text", value="Yay", inline=True)
webhook.add_embed(embed)
response = webhook.execute()

说明:

之前使用set_image无效,大概率是因为你传入的是外部图片URL或错误的路径格式。使用attachment://文件名是Discord Webhook引用本地上传附件的标准方式,这样图片就会嵌入到消息内容中,而非单独分离。

内容的提问来源于stack exchange,提问作者user18191682

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 00:29:52