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

99
Views
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 answers
Answer question

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