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

Discord.js v13发送Embed时报Cannot send an empty message错误如何解决

错误触发原因
  • Discord.js v13版本已经正式废弃了原有message事件,替换为messageCreate事件。你仍在监听已废弃的message事件时,事件回调无法拿到完整有效的消息上下文对象,导致调用channel.send方法时传入的embed参数未被正确序列化传递,Discord API接收不到有效消息内容,就会返回50006空消息错误。
  • 补充:你粘贴的代码片段存在缺失,缺少事件回调的闭合括号、Bot登录逻辑也会导致上下文异常,触发同样的报错。
修复方案
  1. 替换监听的事件名称,将client.on("message", function (message) {修改为client.on("messageCreate", function (message) {
  2. 登录Discord开发者后台,进入你的Bot应用设置页,在「Privileged Gateway Intents」分类下开启Message Content Intent权限,否则Bot无法正常读取服务器消息内容,触发逻辑异常。
  3. 补全代码缺失的闭合符号和登录逻辑,确保代码可正常执行。

修正后的参考代码如下:

const { Client, Intents, MessageEmbed } = require("discord.js");
const client = new Client({ 
  intents: [
    Intents.FLAGS.GUILDS, 
    Intents.FLAGS.GUILD_MESSAGES,
    Intents.FLAGS.MESSAGE_CONTENT // 新增消息内容意图
  ] 
});

client.on("messageCreate", function (message) {
    // 可添加判断避免Bot自己触发自己的消息
    if (message.author.bot) return;

    const exampleEmbed = new MessageEmbed()
        .setColor('#0099ff')
        .setTitle('Some title')
        .setURL('https://discord.js.org/')
        .setAuthor('Some name', 'https://i.imgur.com/AfFp7pu.png', 'https://discord.js.org')
        .setDescription('Some description here')
        .setThumbnail('https://i.imgur.com/AfFp7pu.png')
        .addFields(
            { name: 'Regular field title', value: 'Some value here' },
            { name: '\u200B', value: '\u200B' },
            { name: 'Inline field title', value: 'Some value here', inline: true },
            { name: 'Inline field title', value: 'Some value here', inline: true },
        )
        .addField('Inline field title', 'Some value here', true)
        .setImage('https://i.imgur.com/AfFp7pu.png')
        .setTimestamp()
        .setFooter('Some footer text here', 'https://i.imgur.com/AfFp7pu.png');

    message.channel.send({ embeds: [exampleEmbed] });
});

// 替换为你自己的Bot Token完成登录
client.login('你的Bot Token');

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.26 12:15:03