Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

210
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda