
discord.py 2.0+ 中使用 slash 命令发送嵌入(embed)时,若误传 `embeds=[embed]`(列表形式),将导致“application did not respond”错误;正确用法是传入单个 `embed=` 参数。
在 Discord.py 2.0+(即 discord.py 重写版,基于 app_commands)中,slash 命令的响应机制与传统消息事件不同:必须在 3 秒内对交互(Interaction)作出首次响应,否则 Discord 会判定应用无响应并显示 “Application did not respond”。而常见错误之一,正是混淆了 send_message() 方法的参数签名。
? 核心问题定位
你当前代码中使用了:
await ctx.response.send_message(embeds=[embed])
但 ctx.response.send_message() 不接受 embeds 参数(该参数仅存在于 channel.send() 等非交互响应方法中)。它只支持 embed=(单个 discord.Embed 对象),而非 embeds=(列表)。传入 embeds=[embed] 会导致参数被忽略、响应未被正确触发,最终超时失败。
✅ 正确写法应为:
await ctx.response.send_message(embed=embed)
✅ 完整修正示例
以下是修复后的完整 slash 命令代码(含关键注释):
@bot.tree.command(name="avatar", description="Show a member's avatar")
async def avatar(ctx: discord.Interaction, member: discord.Member):
# 注意:使用 member.display_avatar 而非 member.avatar(更健壮,兼容用户未设置头像场景)
embed = discord.Embed(
title="?️ Avatar",
description=f"{member.mention}'s profile picture!",
color=discord.Color.blurple()
)
embed.set_image(url=member.display_avatar.url) # 推荐使用 display_avatar 并调用 .url
embed.set_footer(
text=f"Requested by {ctx.user.display_name}",
icon_url=ctx.user.display_avatar.url
)
# ✅ 关键修正:使用 embed=,而非 embeds=[...]
await ctx.response.send_message(embed=embed)⚠️ 其他重要注意事项
- ctx.message 在 slash 命令中不可用:ctx.message.author 和 ctx.message.author.avatar 会引发 AttributeError。请改用 ctx.user(代表触发命令的用户)及其 display_avatar 属性。
- 避免 .avatar → 改用 .display_avatar:member.avatar 可能为 None(如用户未设置头像),而 member.display_avatar 总会返回一个有效 URL(默认为 Discord 默认头像)。
- 响应时效性:所有 ctx.response.* 调用必须在 3 秒内完成;若需异步耗时操作(如 API 请求),请先调用 await ctx.response.defer(),再用 await ctx.followup.send(...) 发送结果。
- 同步命令:确保 bot.tree.sync() 已成功执行(如 on_ready 中),且 bot 拥有 applications.commands 权限,并已在测试服务器启用开发者模式与命令同步。
? 总结
“Application did not respond” 错误通常不是网络或权限问题,而是交互响应逻辑错误。牢记三点:
- slash 命令响应必须用 ctx.response.send_message(embed=...),不是 embeds=[...];
- 交互对象(ctx)中无 message 属性,一律使用 ctx.user / ctx.guild 等原生属性;
- 所有响应必须及时——超时即失败,无重试机制。
遵循以上规范,即可稳定发送 Embed 响应,彻底告别静默失败。










