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

Discord.js v14 TypeError求助:SlashCommandbuilder不是构造函数

解决Discord.js v14中SlashCommandBuilder构造函数错误

问题原因

出现TypeError: SlashCommandbuilder is not a constructor的核心原因是大小写拼写错误。Discord.js v14官方定义的构造函数名称是SlashCommandBuilder(最后一个字母B为大写),而你代码中写成了小写的SlashCommandbuilder,导致Node.js无法识别该构造函数。

修复方案

1. 修正commands/ping.js中的拼写错误

将导入和实例化语句里的SlashCommandbuilder全部替换为SlashCommandBuilder:

const { SlashCommandBuilder } = require("@discordjs/builders"); 
module.exports = {
    data: new SlashCommandBuilder()
        .setName("ping")
        .setDescription("Pong."),
    async execute(interaction)
    {
        interaction.reply("Pong!"); 
    }
}

2. 后续注意事项

Discord.js的API对大小写敏感,所有官方提供的类、构造函数、枚举值都需要严格遵循文档中的大小写格式,避免类似拼写错误。

验证修复

修改完成后重新启动机器人,终端的构造函数错误会消失,/ping命令可以正常完成注册并响应交互。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.19 13:20:29