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

199
Visualizações
if the embed does not have author.name it throws me an error

if the read embed does not have author.name, it stops working and sends an error

ERROR C:\Users\windows 10\Desktop\bot_keytritz\index.js:64 if(embed[i].author.name.length >= 0) ^

TypeError: Cannot read properties of null (reading 'name')

CODE
    if(message.embeds.length >= 0) 
    // Check if the Message has embed or not
    {
      let embed = message.embeds
      // console.log(embed) just a console.log
      for(let i = 0; i < embed.length; i++)
      // Loop it since in v13 you can send multiple embed in single message
      {
        if(embed[i].author.name === null) return;
        // check each embed if it has title or not, if it doesnt then do nothing
        {
        if(ListClaims.includes(embed[i].author.name.toLowerCase()))
        // check each embed if it includes word or not
        {
            message.react('🎉')
        }
        }
      }
    }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Then why you won't check if it exist before accessing? There are 2 ways to do it.

  1. Modern one with Optional Chaining operator

if (embed[i]?.author?.name === null) return;

or an old one with

if (!embed[i] || !embed[i].author || embed[i].author.name === null) return;
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