I have this code
const Command = require("../Structures/Command.js");
const Discord = require("discord.js");
const { menu } = require("../data/menu.json");
let x = 0;
let menuEmbed = new Discord.MessageEmbed()
.setColor("#FFA500")
.setTitle("Menu")
.setDescription("Here are the cool things you can order with an \"order\" command")
for(x < menu; x++;){
menuEmbed.addField( menu[x].charAt(0).toUpperCase() + menu[x].slice(1).replace("_", " "), "```id:" + menu[x] + "```" );
}
module.exports = new Command({
name: "menu",
description: "Gives you a menu",
async run(message, args, client){
message.reply(menuEmbed);
}
});
What I want it to do is to add a field for each thing in the menu.json. Is it even possible?
If your menu is just defined as an Array (as I suspect by your comment) then just changing the code for the for-loop should suffice:
for (var entry in menu){
menuEmbed.addField(menu[entry].charAt(0).toUpperCase() + menu[entry].slice(1).replace("_", " "), "```id:" + menu[entry] + "```" )
}
Or you could use a simple forEach loop and ditch he iterator:
menu.forEach(food => {
menuEmbed.addField(food.charAt(0).toUpperCase() + food.slice(1).replace("_", " "), "```id:" + food + "```" )
})
Note:
Array.forEachis said to be slower
Also: keep in mind, that there is a limited number of fields an Embed can have