15 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!Hello, I need a little help because I have an error in the slashcommands. Here is the error:
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))thats not an error
thats code
also
its .toUpperCase()
I can not see the problem ToUpperCase in my code
what?
that code is really messy
and invalid
use that
Does that mean I have to replace it with something else?
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.permissions === "Aucune" ? null : command.permissions)
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))
}
}
commands.push(slashcommand);
})
const rest = new Discord.REST({ version: "10" }).setToken(bot.token)
await rest.put(Routes.applicationCommands(bot.user.id), { body: commands })
console.log("Les commandes sont prêtes");
}
the code above is pretty much unreadable
and i dont see why you would use it
because you can just use slashcommandbuilders, export them and call .toJSON() on them
no need for this kind of magic
XD simple and effective
thanks
I’m sorry but I’m really struggling to
understand what
this part
You should know how to import and export stuff
Well I didn’t have config.json before
use what you have
whether its dotenv or a json config
Not really djs related