For my bot in discord, I would like a !help command that loops through all commands, gets the name, and returns them in a message back to the user. I have created fs to loop through my /commands/ folder:
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.extraCommands.set(command.name, command);
}
console.log(client.extraCommands);
Returns a Collection Map that looks like: (cropped for sake of simplicity)
Collection [Map] {
'args-info' => {
name: 'args-info',
execute: [Function: execute]
},
'channel-info' => {
name: 'channel-info',
execute: [Function: execute]
}
All I need is to store the name of each command into an array.
I've tried looping through to get the key but that doesn't seem to work...
Thanks in advance for any help
Map, you can loop throughfor(const key of client.extraCommands.keys()){/* Add key to an array */}or just useclient.extraCommands.keys()since it's an iterator