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

如何在Discord.py中通过单次channel.send使Embed显示在Files之前?

解决Discord.py中Embed在附件上方显示的问题

你当前通过await channel.send(files=files, embed=embedvar)发送消息时,附件(图片)显示在Embed上方,这是因为Discord客户端默认会将附件优先渲染在Embed之前。如果想要实现Embed在上、附件在下的效果,无法通过单次channel.send()直接实现(因为Discord API会同时传递Embed和附件数据,客户端渲染顺序由平台决定),但可以通过先发送Embed,再编辑消息添加附件的方式实现同一条消息内的顺序调整,具体代码如下:

embedvar = discord.Embed(title=f'🔗 {name}', description=text, url=link)
embedvar.set_author(name=user, icon_url=img)
embedvar.add_field(name="", value="", inline=True)
embedvar.set_footer(text=f'Posted on: Requested by:')

files = []
for filename in os.listdir(path):
    file_path = os.path.join(path, filename)
    files.append(discord.File(file_path, filename))

channel = bot.get_channel(*channel)
# 先发送Embed
sent_message = await channel.send(embed=embedvar)
# 编辑消息添加附件,此时附件会显示在Embed下方
await sent_message.edit(files=files)

补充说明

  • 这种方式本质是对同一条消息进行两次操作,但最终呈现给用户的是一条包含Embed和附件的消息,且Embed位于附件上方。
  • 你了解的Discord.js中.send().then()方案,逻辑和这个一致:先发送Embed得到消息对象,再通过消息对象添加附件。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 21:32:24