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

Discord.js v14 TypeError: (intermediate value).setColor不是函数求助

问题修复方案

错误原因

Discord.js v14及以上版本中,嵌入消息的构造类是EmbedBuilder,而非你代码里的Embed。使用错误的类实例化对象后,对象不存在setColor这类方法,因此抛出类型错误。

修复步骤

  1. 修正导入语句,替换为正确的类名:
const { EmbedBuilder } = require("discord.js");
  1. 将实例化嵌入对象的代码中的new Embed()改为new EmbedBuilder(),其余链式调用逻辑保持不变:
const embed = new EmbedBuilder()
  .setColor("#FF0000")
  .setTitle("🏓 Pong!")
  .setDescription(`Latency : ${client.ws.ping}ms`)
  .setTimestamp()
  .setFooter({ text: `Requested by ${interaction.user.tag}`, iconURL: `${interaction.user.displayAvatarURL()}` });
  1. (可选优化)如果你的斜杠命令没有提前延迟回复,建议将interaction.followUp改为interaction.reply,避免触发交互超时错误:
interaction.reply({ embeds: [embed] });

修复后的完整代码

const { EmbedBuilder } = require("discord.js");

module.exports = {
  name: "ping",
  description: "Returns websocket latency",

  run: async (client, interaction) => {
    const embed = new EmbedBuilder()
      .setColor("#FF0000")
      .setTitle("🏓 Pong!")
      .setDescription(`Latency : ${client.ws.ping}ms`)
      .setTimestamp()
      .setFooter({ text: `Requested by ${interaction.user.tag}`, iconURL: `${interaction.user.displayAvatarURL()}` });
    interaction.reply({ embeds: [embed] });
  },
};

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.25 06:39:22