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

Discord.js报错:SlashCommandBuilder is not a constructor求助

解决Discord.js中SlashCommandBuilder不是构造函数的报错
  • 版本不兼容问题:SlashCommandBuilder是Discord.js v13及以上版本才提供的API,如果你安装的Discord.js版本低于v13,就会触发这个报错。

    • 检查当前版本:在项目根目录运行命令 npm list discord.js
    • 升级到最新稳定版:执行 npm install discord.js@latest
  • 顺带修复代码里的其他小问题:

    • 你写的是Slash命令,但isSlashGame设成了false,改成true才能让游戏正确响应交互
    • playerOnlyMessage里的cam ise是拼写错误,应该是can use
    • winMessage里的**(word)占位符格式错误,要改成{word}**才能正常显示答案

修复后的完整代码:

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

module.exports = {
    data: new SlashCommandBuilder()
        .setName('wordle')
        .setDescription("Play the wordle game!"), 
    async execute (interaction) {
        const Game = new Wordle({ 
            message: interaction, 
            isSlashGame: true,
            embed: {
                title: 'Wordle',
                color: '#5865F2'
            },
            customword: null,
            timeoutTime: 60000,
            winMessage: 'You won! The word was **{word}**',
            loseMessage: 'You lost! The word was **{word}**',
            playerOnlyMessage: 'Only {player} can use these buttons'
        });
        
        Game.startGame();
        Game.on('gameOver', result => {
            return;
        })
    }    
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 14:15:01