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

Discord Bot注册斜杠命令报错:Command name is invalid

解决Discord斜杠命令注册时的APPLICATION_COMMAND_INVALID_NAME错误

出现DiscordAPIError[50035]: Invalid Form Body且提示name[APPLICATION_COMMAND_INVALID_NAME]: Command name is invalid,核心原因是违反了Discord斜杠命令的命名规则:

  • 命令名称只能使用小写字母(a-z)、数字(0-9)和连字符(-)
  • 长度必须在1到32字符之间
  • 不允许出现大写字母、空格或其他特殊字符

你的代码中命令名称'Apostole'包含大写字母,不符合规则,导致注册失败。

修改后的代码如下:

require('dotenv').config();
const { REST, Routes } = require('discord.js');

const commands = [
    {
        name: 'apostole', // 改为全小写
        description: 'Informs you of the horrors awaiting on the other side',
    }
];

const rest = new REST({ version: '10' }).setToken(process.env.TOKEN);

(async () => {
    try {
      console.log('The Apostole is thinking...');
        
      await rest.put(
        Routes.applicationGuildCommands(
          process.env.CLIENT_ID, 
          process.env.GUILD_ID
          ),
        { body: commands }
      );
      
      console.log('The Apostole has answered.');
    } catch (error) {
      console.log(`Unexpected Apostole Intervention.: ${error}`);
    }
})();

将命令名称改为全小写的apostole后,重新运行代码即可正常注册斜杠命令。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 07:27:12