Hello ! I am a newbie to code and i needed help for this … After ive done the slash commands part ,everytime i try to run my code i get these errors .. May someone help me ? Thanks in advance !
ValidationError: Expected undefined or null
at NullishValidator.handle (C:UsersBryanDesktopVegetable [email protected]:748:79)
at NullishValidator.run (C:UsersBryanDesktopVegetable [email protected]:187:23)
at UnionValidator.handle (C:UsersBryanDesktopVegetable [email protected]:1083:32)
at UnionValidator.parse (C:UsersBryanDesktopVegetable [email protected]:201:88)
at validateDMPermission (C:UsersBryanDesktopVegetable [email protected]:952:25)
at MixedClass.setDMPermission (C:UsersBryanDesktopVegetable [email protected]:1434:5)
at C:UsersBryanDesktopVegetable v1.2LoadersloadSlashCommands.js:14:10
at Collection.forEach ()
at module.exports (C:UsersBryanDesktopVegetable v1.2LoadersloadSlashCommands.js:9:18)
at module.exports (C:UsersBryanDesktopVegetable v1.2Eventsready.js:6:11) {
validator: ‘s.nullish’,
given: ‘true’
},
ValidationError: Expected a boolean primitive
at BooleanValidator.handle (C:UsersBryanDesktopVegetable [email protected]:582:71)
at BooleanValidator.run (C:UsersBryanDesktopVegetable [email protected]:187:23)
at UnionValidator.handle (C:UsersBryanDesktopVegetable [email protected]:1083:32)
at UnionValidator.parse (C:UsersBryanDesktopVegetable [email protected]:201:88)
at validateDMPermission (C:UsersBryanDesktopVegetable [email protected]:952:25)
at MixedClass.setDMPermission (C:UsersBryanDesktopVegetable [email protected]:1434:5)
at C:UsersBryanDesktopVegetable v1.2LoadersloadSlashCommands.js:14:10
at Collection.forEach ()
at module.exports (C:UsersBryanDesktopVegetable v1.2LoadersloadSlashCommands.js:9:18)
at module.exports (C:UsersBryanDesktopVegetable v1.2Eventsready.js:6:11) {
validator: ‘s.boolean’,
given: ‘true’
}
]
}
Node.js v18.14.0
Here is my loadSlashCommands file :
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 !")
}
Here is my ready file :
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 !`)
}
I have tried to search the reasons of these errors like changing values etc.. But as i said , im new to coding and i dont understand very well ..