0

So I've been starting off with Javascript and thus far I have loved the language. I have now hit a roadblock in my learning and have not been able to find an answer on here or Google as a whole. So, I'm coding a Discord bot using the Discord.JS library and I have an array that holds all of my commands kinda like so..

global.commands = [];

I then store them by just doing a simple something like so..

commands["ping"] = JSFileThatHasTheCommand;

Then when I want to run the command it's as simple as so..

commands["ping"].run(msg, args);

Anyways you get the gist as to what I mean. So, I have the array like that and I want to use a for loop to loop through the array and add the information for the command to a variable for later use, something like this..

let someRandomVar;
var length = Object.keys(commands).length;
for (var i = 0; i < length; i++)
{
    // Store the the data in the variable? Note: This part does not work
    // Info is another {} array that holds the description of the command as 
    // a string and is accessed via exports.. Not sure how to grab the 
    // previously stored commandfile by using an int to grab it although the 
    // key is the command name as a string..
    someRandomVar += commands[i].info.description

}

Any and all help is cherished and thanked. Not sure if it's even possible but figured some of you Javascript experts would give a better answer over my assumptions.

Jake Adams
  • 25
  • 7

0 Answers0