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

369
Views
Discord.js use try catch statement to handle api error

Hello I am currently attempting to catch a discord api error with the try catch statement

However for some reason this does not work and my app still stops executing and gives me the following message

 There was an uncaught error DiscordAPIError: Cannot send messages to this user // Example

How do I catch api errors with a try and catch block and I cannot use a .catch expression after calling the function

Here is my code

try {
    interaction.user.send("Remember")
}
catch(DiscordAPIError) {
    console.log("Oh no")
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you want to use a synchronous try/catch block, you need to put it in an async function and await the promise from interaction.user.send:

await interaction.user.send("Remember")
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!