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

178
Views
Check if user with a specific ID exists

I know you can get server member using let user = guild.members.cache.get('ID') and then check if member exists using if(!user) return, but how can I get a user with specific ID and check if this user exist at all if my bot doesn't share any servers with them?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This would be more suited as a comment to another answer but I can't yet add them so;

The second method in the answer I'm referencing is the best way, however is incorrect. client.users.fetch() does not return undefined. If no user exists, it errors, so instead you must do

let user;
try {
    user = await client.users.fetch("id", { force: true, cache: true }); // force skips cache checking so they don't need to be cached by the bot, cache will cache the user
} catch(err) {
    user = undefined;
}

// or
client.users.fetch("id", { force: true, cache: true })
.then(user => {
    // do something
})
.catch(err => {
    // user doesn't exist or another error occurred 
})
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!