Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

205
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda