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 usewinMessage里的**(word)占位符格式错误,要改成{word}**才能正常显示答案
- 你写的是Slash命令,但
修复后的完整代码:
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
相关产品推荐
相关产品推荐

