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

208
Vistas
How can i createoptional fields embed field on my discord bot?

This is my simple code. and i need optional fields (fd, fdd) on my slesh command embed builder. how can i do?empty fields no delete so.if my field value is empty, then don't show up, and if the field is have a value then add on embed. optional values.

    const desc = options.getString("leírás");
    const fd1 = options.getString("field1");
    const fd2 = options.getString("field2");
    const fd3 = options.getString("field3");
    const fdd1 = options.getString("fielddesc1");
    const fdd2 = options.getString("fielddesc2");
    const fdd3 = options.getString("fielddesc3");
    
    //cache.find(role => role.id === "967822275355246732");A

    const Response = new MessageEmbed()
    .setColor("RANDOM")
    .setDescription(`${interaction.member} létrehozott egy <@&963762743150796810>-t, **${type}** kategóriával.`)
    .setThumbnail('https://media.discordapp.net/attachments/967828295121006592/969690574674354337/958794200999145513.png')
    .addField("⟬Cím⟭", `${title}`)
    .addField("⟬Leírás⟭", `${desc}`)
    .addField(`${fd1}`, `${fdd1}`)
    .addField(`${fd1}`, `${fdd1}`)
    .addField(`${fd2}`, `${fdd2}`)
    .addField(`${fd3}`, `${fdd3}`)
    .setFooter({text: "*`Telihold, Tele mosoly :)`*"})
    .setTimestamp()
    const message = await interaction.reply({embeds: [Response], fetchReply: true});
    message.react('🔥')

        .then(() => message.react('❤️'))
        .catch(error => console.error('Nem tudom betölteni az egyik hangulatjelet', error));
}

}

///i tried this way but not good///

    .addField("⟬Cím⟭", `${title}`)
    .addField("⟬Leírás⟭", `${desc}`)
    .setFooter({text: "*`Telihold, Tele mosoly :)`*"})
    .setTimestamp()
    const message = await interaction.reply({embeds: [Response], fetchReply: true});
    message.react('🔥')
        .then(() => message.react('❤️'))
        .catch(error => console.error('Nem tudom betölteni az egyik hangulatjelet', error));
        if (`${fd1}`)
        Response.addField(`${fd1}`, `${fdd1}`)
        if (`${fd2}`)
        Response.addField(`${fd1}`, `${fdd1}`)
        if (`${fd3}`)
        Response.addField(`${fd1}`, `${fdd1}`)
        return interaction.reply({embeds: [Response], fetchReply: true});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Use an if statement to check if the variable exists first.

let Response = new MessageEmbed()
        .setColor("RANDOM")
        .setDescription(` egy <@&963762743150796810>-t, kategóriával.`)
        .setThumbnail('https://media.discordapp.net/attachments/967828295121006592/969690574674354337/958794200999145513.png')
        .addField("⟬Cím⟭", `abc`)
        .addField("⟬Leírás⟭", `def`)
        .setFooter({ text: "*`Telihold, Tele mosoly :)`*" })
        .setTimestamp()

if (fd1) {
    Response.addField(`${fd1}`, `${fdd1}`)
}

Then you will be able to avoid it saying "null" when the variable isn't set.

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