I'm making a discord.js bot where all the command data is stored in a JSON file and when the help command is run, I want it to iterate through the JSON, at the level the user entered.
So far, I've managed to check if the value entered is a command or a category, and I have been able to console.log all the information and it shows the correct data I want to display on the embed.
For example, in my JSON file I have:
{
"category1": {
"command1": {
"Aliases": [],
"Description": "Runs a command"
}
}
}
When I do the console.log() when the user runs g!help category1 it outputs:
command1
Runs a command
and when it sends the embed I get:
[object Object]
undefined
Here is the part of the code which iterates through the JSON and adds the data to the embed:
for (ctg in help_data) {
if (args[0] === ctg) {
embed.setTitle(ctg)
for (command in help_data[ctg]) {
var cmd = command
var desc = help_data[ctg][command].Description
console.log(cmd)
console.log(desc)
embed.addField({
"name": cmd,
"Value": desc
})
}
}
}
I don't understand why it changes between the console.log and the embed.addField, if someone could please explain why this happens and how I can fix it, that would be amazing!