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

Discord.js导入命令文件触发ExpectedConstraintError报错求助

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

问题原因

你的报错核心是Discord Slash命令名称不符合官方格式约束。从报错信息里的正则规则/^[\p{Ll}\p{Lm}\p{Lo}\p{N}\p{sc=Devanagari}\p{sc=Thai}_-]+$/u可以明确:

  • 命令名称必须全小写(支持梵文、泰文等特定文字)
  • 仅允许搭配数字、下划线_或连字符-
  • 禁止使用大写字母、空格及其他特殊字符

你在hi.js中使用了setName('Hi'),其中大写的H直接违反了该规则,导致Discord.js依赖的校验库@sapphire/shapeshift抛出格式错误。

解决方案

修改hi.js中的命令名称为全小写即可:

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

module.exports = {
    data: new SlashCommandBuilder()
        .setName('hi') // 将'Hi'改为全小写的'hi'
        .setDescription('Get introduced to the bot'),
    async execute(interaction) {
        await interaction.reply('Hi I am Herote bot I was created by a Dog names barood /help for commands');
    },
};

修改后重新运行代码,命令导入与注册流程即可正常执行。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.12 09:39:30