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

Discord.js 14 Slash命令createEmbed报错ExpectedConstraintError求助

解决Discord.js 14 Slash命令格式错误问题

错误原因分析

从报错信息里的正则规则/^[\p{Ll}\p{Lm}\p{Lo}\p{N}\p{sc=Devanagari}\p{sc=Thai}_-]+$/u可以明确看出,Discord对Slash命令名称有强制格式要求:

  • 必须全部使用小写字母
  • 仅允许包含小写字母、数字、下划线_、连字符-

你的代码里命令名createEmbed包含大写字母E,直接违反了这个规则,这是触发ExpectedConstraintError的核心原因。另外还有一个拼写错误:excute应该是execute,虽然这不是当前报错的原因,但后续运行会导致方法无法被正确调用,需要一并修正。

修复步骤

  1. 修正命令名称
    将.setName("createEmbed")修改为符合格式的名称,比如.setName("create_embed")或.setName("createembed")。

  2. 修正方法拼写
    把async excute (interaction, client)改为async execute (interaction, client)。

修复后的完整代码

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

module.exports = {
    data: new SlashCommandBuilder()
        .setName("create_embed")
        .setDescription("Create new test Embed!"),
    /**
     * 
     * @param {CommandInteraction} interaction
     * @param {Client} client
     */

    async execute (interaction, client) {
        const exampleEmbed = new EmbedBuilder()
        .setColor(0x0099FF)
        .setTitle('Some title')
        .setAuthor({ name: 'Some name' })
        .setDescription('Some description here')
        .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 },
        )
        .addFields({ name: 'Inline field title', value: 'Some value here', inline: true })
        .setTimestamp()
        .setFooter({ text: 'Some footer text here' });

        await interaction.reply({
            embeds: [exampleEmbed]
        });
    },
};

后续操作

修改完成后,重新部署你的Slash命令:如果是全局命令需要等待Discord缓存刷新(通常1小时内),如果是服务器专属命令则重新同步到目标服务器,之后即可正常使用该命令创建Embed。

内容的提问来源于stack exchange,提问作者감기여요

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.04 07:55:17