Getting slash commands

const commandsColl = await client.application.commands.fetch(); I use this to get all the commands and then I try to iterate through the collection with
for (const command in commandsColl) {
//and i do something here
console.log(command);
}
for (const command in commandsColl) {
//and i do something here
console.log(command);
}
But the terminal doesnt say anything so the for loop never started
13 Replies
d.js toolkit
d.js toolkit3mo ago
- 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! - Marked as resolved by OP
Papalo007
Papalo007OP3mo ago
more specifically i want the id of the command, but rn the loop doessnt ever start
treble/luna
treble/luna3mo ago
do you have global or guild commands registered
Papalo007
Papalo007OP3mo ago
should be global although i tried interaction.guild.commands.fetch(); and it fetched nothing all commands are global
treble/luna
treble/luna3mo ago
loop over .values
d.js docs
d.js docs3mo ago
Converting a Collection to an array You only need to convert it to an array if you need the index of an entry: - Iteration (looping) is possible with for...of over Collection#values or forEach - You can transform a Collection to an array with Collection#map - If you need indices, you can get the array using [...collection.values()]
Papalo007
Papalo007OP3mo ago
so for(const command in commandsColl.values())?
treble/luna
treble/luna3mo ago
yes also its of
Papalo007
Papalo007OP3mo ago
when i do that it says it's not iterable and when I use in it doesn't do anything oh nvm i got an error now
treble/luna
treble/luna3mo ago
show the full code and error
Papalo007
Papalo007OP3mo ago
gimme one sec im tryin to see if i can figure it out myself ok i believe the loop worked. I just dont know how to get the id of the command
Papalo007
Papalo007OP3mo ago
ohhh wait the error wasnt the id so basically im adding stuff to an embed and i happened to have one of these right click -> Apps thingy and it didnt have a description so one of the embed values was empty ok ty for helpin with the loop!
Want results from more Discord servers?
Add your server