Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

110
Views
Add field for an each element in .json file

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?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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.forEach is said to be slower

Also: keep in mind, that there is a limited number of fields an Embed can have

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!