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

191
Views
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 answers
Answer question

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 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!