Discord Bot发送消息未生成Embed嵌入格式,相关接口调用无效如何解决?
问题原因及修复方案
1. 核心失效原因
你当前使用的是discord.js v12及更早版本的Embed传参写法,v13、v14版本对Embed相关API做了破坏性变更,旧写法会直接被框架忽略,仅发送普通文本内容。
2. 修复步骤
- 确认你的Bot在对应频道拥有
嵌入链接权限,权限缺失也会导致Embed不渲染 - 调整消息传参结构,废弃旧的双参数写法和
embed单对象字段,改用官方推荐的EmbedBuilder构造Embed,放入embeds数组字段中传递
3. 可直接运行的代码示例
// 引入官方Embed构造工具 const { EmbedBuilder } = require('discord.js'); // 构造Embed实例 const targetEmbed = new EmbedBuilder() .setColor(3447003) .setDescription("A very simple Embed!"); // reply发送写法 message.reply({ content: 'some reply', embeds: [targetEmbed] }); // channel.send写法同理 message.channel.send({ content: 'some reply', embeds: [targetEmbed] });
4. 兼容写法(无需引入EmbedBuilder)
如果不想使用构造类,也可以直接传递符合规范的普通对象,注意字段名必须为embeds且值为数组:
message.reply({ content: 'some reply', embeds: [{ color: 3447003, description: "A very simple Embed!" }] });
内容的提问来源于stack exchange,提问作者Nothere
相关产品推荐
相关产品推荐

