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

181
Views
TypeError: Cannot read properties of undefined (reading 'catch')

I am trying to get channel with an id or mention, the code itself works but when user gives wrong ID it says: TypeError: Cannot read properties of undefined (reading 'catch')

Can anyone help me?

I tried this:

message.guild.channels.cache.find(channel => channel.id == args[0]).catch(err => {});

And this:

message.guild.channels.cache.get(args[0]).catch(err => {});

These both things give me error.

Heres the code:

if (args[0].startsWith("<#")) channel = message.mentions.channels.first();
        else channel = message.guild.channels.cache.get(args[0]).catch(err => {
    //do stuff
    })
    
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Okay so i found out the answer with help of @JeremyThille: `When the id is wrong it tries to null.catch()

I removed catch from the code and added

if(!channel) //do stuff

Thanks @JeremyThille

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!