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

discord.js v14.7.1创建Embed时出现类继承TypeError错误

修复discord.js v14.7.1中/help斜杠命令的错误

错误原因

  1. Command类不存在:discord.js v14没有内置的Command基类,你之前的继承写法是旧版本第三方框架(比如discord-akairo)的用法,直接导入会得到undefined,导致继承报错。
  2. MessageEmbed已被移除:v14中MessageEmbed替换为EmbedBuilder。
  3. 消息发送格式变更:发送Embed时不再使用embed字段,而是用embeds数组包裹。
  4. 斜杠命令定义方式更新:v14通过SlashCommandBuilder来定义斜杠命令,而非自定义类继承。

修复后的完整代码

const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');

module.exports = {
  // 定义斜杠命令的基本信息
  data: new SlashCommandBuilder()
    .setName('help')
    .setDescription('List all available commands.'),
  
  // 执行命令的逻辑
  async execute(interaction) {
    const helpEmbed = new EmbedBuilder()
      .setColor('#F8F7D8')
      .setTitle('TITLE')
      .setURL('URL')
      .setAuthor({
        name: 'NAME',
        iconURL: 'URL',
        url: 'URL',
      })
      .setDescription('Commands for NAME')
      .setThumbnail('URL')
      .addFields(
        { name: '/play', value: 'Used to play the music' },
        { name: '\u200B', value: '\u200B' },
        { name: '/pause', value: 'Used to pause the music', inline: true },
        { name: '/mp3', value: 'Used to convert a youtube link to an mp3', inline: true },
        { name: '/skip', value: 'Used to skip the music', inline: true }
      )
      .setImage('URL')
      .setTimestamp()
      .setFooter({
        text: 'NAME',
        iconURL: 'URL',
      });

    // 回复斜杠命令交互,发送Embed
    await interaction.reply({ embeds: [helpEmbed] });
  },
};

关键修改说明

  • 用SlashCommandBuilder替代自定义类,正确定义斜杠命令的名称和描述。
  • 替换MessageEmbed为EmbedBuilder,适配v14的API。
  • 将message.channel.send({ embed: help })改为interaction.reply({ embeds: [helpEmbed] }),因为斜杠命令的交互对象是Interaction而非普通Message,且v14要求Embed放在数组中。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 04:25:40