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

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

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