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
相关产品推荐
相关产品推荐

