Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

112
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda