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
But the terminal doesnt say anything so the for loop never started13 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!
- ✅
Marked as resolved by OPmore specifically i want the id of the command, but rn the loop doessnt ever start
do you have global or guild commands registered
should be global
although i tried
interaction.guild.commands.fetch();
and it fetched nothing
all commands are globalloop over .values
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()]
so
for(const command in commandsColl.values())
?yes
also
its of
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 nowshow the full code and error
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
https://canary.discord.com/channels/222078108977594368/1143952258321612922
they have an id property
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!