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

101
Vistas
Bot crashed when trying to DM

My Discord bot sometimes sends a message directly to the user, but if user turned off the messages from strangers it crashes.

Is there some If function that will check if you can send a message to this user? Or maybe some command, that will try to send a message to the user, but if it won't work, bot will ignore it and go on? I tried "try" but it doesn't work DiscordAPIError: Cannot send messages to this user

try{
   await client.users.cache.get(`${id}`).send('hello',{
      embed:embed1,
      });
   let messageEmbed1 = await client.users.cache.get(`${id}`).send({embeds: [embed1]})
   } catch (error) {
   console.error(error);
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

send function is a async function, therefore you need to chain catch function instead of try catch scoping them.

await client.users.cache.get(`${id}`).send('hello',{
      embed:embed1,
      });
   let messageEmbed1 = await client.users.cache.get(`${id}`).send({embeds: [embed1]}).catch(e=>{console.log(`Saved bot from crash, error:\n${e}`)});
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