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

discord.js v12发消息触发DiscordAPIError: Cannot send an empty message报错

问题解决方法

报错原因

  • discord.js v13及后续版本调整了消息发送接口规则:channel.send()方法不再支持直接传入MessageEmbed实例作为参数,必须将Embed对象放到配置项的embeds数组中,否则接口会识别为你要发送的文本内容为空,触发对应报错
  • 额外要注意的边界情况:如果原消息没有文本内容(比如仅发送图片、表情贴纸),message.content为空,也会导致Embed的描述为空触发校验错误
  • 代码检查:确认你代码中两处频道ID的取值正确,判断触发条件的原频道ID硬编码值"CHANNELID",和目标发送频道的CHANNELID变量不要混淆

修复后参考代码

// v13+版本请使用messageCreate事件替代已废弃的message事件
client.on("messageCreate", (message) => {
    // 过滤机器人自身发送的消息,避免循环触发
    if (message.author.bot) return;
    if (message.channel.id === "原监听频道ID") {
      const embed = new MessageEmbed()
      // 处理content为空的情况
      .setDescription(message.content || "该消息无文本内容")
      .setColor("#E74C3C")
      .setTimestamp()
      .setAuthor(message.author.tag, message.author.displayAvatarURL({ dynamic: true }))
      // 正确的传参格式,把embed放到embeds数组中
      message.client.channels.cache.get("目标发送频道ID").send({
        embeds: [embed]
      });
    }
})

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.05 10:24:01