你好我是一个代码新手,我需要帮助。。。在我完成斜线命令部分之后,每次我尝试运行代码时都会出现这些错误。。有人可以帮我吗?提前感谢!
ValidationError:NullishValidator.handle(C:\Users\Bryan \Desktop\Chegetable v1.2)处应为未定义或null\node_modules@sapphire\shapeshift\dist\index.js:748:79)在NullishValidator.run(C:\Users\Bryan\Desktop\Chegetablev1.2\node_modules@sapphire\shapeshift\dist\index.js:187:23),位于UnionValidator.handle(C:\Users\Bryan\Desktop\Vegetable v1.2\node_modules@sapphire\shapeshift\dist\index.js:1083:32),位于UnionValidator.parse(C:\Users\Bryan\Desktop\Vegetable v1.2\node_modules@sapphire\shapeshift\dist\index.js:20:88)在validateDMPermission(C:\Users\Bryan\Desktop\Chegetablev1.2\node_modules@discordjs\builders\dist\index.js:952:25)在MixedClass.setDMPermission(C:\Users\Bryan\Desktop\Vegetable v1.2\node_modules@discordjs\builders\dist\index.js:1434:5),位于C:\Users\Bryan \Desktop\Vegetablev1.2\Loaders\loadSlashCommands.js:14:10,位于module.exports(C:\Users\布赖恩·Desktop\Vegetable v1.2\Loaders\loadSlashCommands.js:9:18)的模块.exports(C:\Users\Bryan \Desktop\ VegetableV1.2\Events\ready.js:6:11){validator:'s.nullash',给定为:'true'},ValidationError:BooleanValidator.handle(C:\Users\Bryan \Desktop\Vegetable v1.2)应为布尔原始值\node_modules@sapphire\shapeshift\dist\index.js:582:71)在BooleanValidator.run(C:\Users\Bryan\Desktop\Vegetablev1.2\node_modules@sapphire\shapeshift\dist\index.js:187:23),位于UnionValidator.handle(C:\Users\Bryan\Desktop\Vegetable v1.2\node_modules@sapphire\shapeshift\dist\index.js:1083:32),位于UnionValidator.parse(C:\Users\Bryan\Desktop\Vegetable v1.2\node_modules@sapphire\shapeshift\dist\index.js:20:88)在validateDMPermission(C:\Users\Bryan\Desktop\Chegetablev1.2\node_modules@discordjs\builders\dist\index.js:952:25)在MixedClass.setDMPermission(C:\Users\Bryan\Desktop\Vegetable v1.2\node_modules@discordjs\builders\dist\index.js:1434:5),位于C:\Users\Bryan\Desktop\Vegetablev1.2\Loaders\loadSlashCommands.js:14:10,位于module.exports(C:\Users\布赖恩·Desktop\Vegetable v1.2\Loaders\loadSlashCommands.js:9:18),位于modules.exports(C:\Programs\Bryan\Desktop\Chegetablev1.2 \Events\ready.js:6:11){validator:'s.boolean',给定为'true'}]}
Node.js v18.14.0
这是我的loadSlashCommands文件:
const Discord = require('discord.js') const { REST } = require('@discordjs/rest') const { Routes } = require('discord.js') module.exports = async bot => { let commands = []; bot.commands.forEach(async command => { let slashcommand = new Discord.SlashCommandBuilder() .setName(command.name) .setDescription(command.description) .setDMPermission(command.dm) .setDefaultMemberPermissions(command.permission === "Aucune" ? null : command.permission) if(command.options?.length >= 1) { for(let i = 0; i < command.options.length; i++) { slashcommand[`add${command.options[i].type.slice(0, 1).toUpperCase() + command.options[i].type.slice(1, command.options[i].type.length)}Option`](option => option.setName(command.options[i].name).setDescription(command.options[i].description).setRequired(command.options[i].required)) } } await commands.push(slashcommand) }) const rest = new REST({version: '10'}).setToken(bot.token) await rest.put(Routes.applicationCommands(bot.user.id), {body: commands}) console.log("Les slash commandes sont crées avec succès !") }
这是我准备好的文件:
const Discord = require("discord.js") const loadSlashCommands = require("../Loaders/loadSlashCommands") module.exports = async bot => { await loadSlashCommands(bot) console.log(`${bot.user.tag} est bien en ligne !`) }
我已经尝试过搜索这些错误的原因,比如改变值等。但正如我所说,我对编码很陌生,我不太理解。。