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

213
Visualizações
Discordjs could not catch a DiscordAPIError

Basically the problem is that even if I wrap the code that causes the error in try catch, the error still stops the code, here's my code.

// snip
try{
    // get user using id "does-not-exist", which does not exist
    // code stops when fetching user
    client.users.fetch('does-not-exist').then(function (user) {
        user.send('hello');
    });
}catch(err){
    console.error('message could not be sent');
}

Why does my code stops even if I wrap it with try catch?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

try/catch should be used in combination with async/await. If you want to use synchronous then/catch, use the respective .catch() callback.

client.users.fetch('does-not-exist')
   .then(function (user) {
        user.send('hello');
   })
   .catch(err => /* error handle */);

If you want to ignore the error void it

.catch(_ => null);

How it would look with async await

try {
   const user = await client.users.fetch('does-not-exist')
} catch (err) {
   /* Handle Error */
}
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