Discord Bot发送Embed报Cannot send an empty message错误咨询
报错核心原因
错误码50006(Cannot send an empty message)是Discord接口返回的通用请求错误,触发条件是调用消息发送接口时,请求体中content、embeds、components、attachments等所有承载消息内容的字段全为undefined或空值,接口判定请求未携带任何有效发送内容,直接拒绝请求。
从你贴的报错请求体可以看到,embeds字段值为undefined,说明你代码中传给message.channel.send()的参数没有被序列化为合法的Embed结构,最终发出去的是空请求。
代码存在的问题
- 版本适配错误:你当前运行环境安装的是v13及以上版本的discord.js,但代码用的是v12及更早版本的API写法。v13版本对消息发送逻辑做了破坏性更新:不再支持直接将
MessageEmbed实例作为参数传入send()方法,必须将实例放入配置对象的embeds数组字段中传递,直接传实例会导致参数解析失败,Embed内容被丢弃。 - 构造函数引用风险:你在execute方法中通过传入的
Discord对象取MessageEmbed构造函数,这种写法如果在主文件传参时漏传、错传discord.js实例,会导致new Discord.MessageEmbed()实际返回undefined,后续链式调用的配置全部无效,最终生成的是无意义的空值。
修复方案
将代码调整为适配v13+版本的写法,优先在模块顶部直接引入Embed构造函数,修正send方法的传参格式:
// 模块顶部直接引入discord.js的Embed构造函数,不要依赖参数传入 const { MessageEmbed } = require('discord.js'); module.exports = { name: 'command', description: "Embeds!", execute(message, args) { const newEmbed = new MessageEmbed() .setColor('#FF0000') .setTitle('This is a title.') .setURL('https://www.youtube.com') .setDescription('This is an embed.') .addFields( {name: 'Field 1', value: 'Text 1'}, {name: 'Field 2', value: 'Text 2'}, {name: 'Field 3', value: 'Text 3'} ) .setImage('https://upload.wikimedia.org/wikipedia/commons/9/9a/Gull_portrait_ca_usa.jpg') // v13+版本要求通过配置对象传递embed,放入embeds数组 message.channel.send({ embeds: [newEmbed] }); } }
如果你使用的是v14版本discord.js,需要将MessageEmbed替换为@discordjs/builders包提供的EmbedBuilder,传参格式保持一致即可。
内容的提问来源于stack exchange,提问作者HazzyTheHazmat
相关产品推荐
相关产品推荐

