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

278
Views
DiscordAPIError: Cannot send messages to this user at RequestHandler.execute

Hey so i made a 'hack' command in my bot as a joke, i want it to dm the author of the message, but whenever i run the command, it just gives me a error, even if the author has open dm's. this is the error:

DiscordAPIError: Cannot send messages to this user

And this is my code:

msg.author.send(`Name:${taggedUser.username},
             ID:${taggedUser.id}
             IP Address:${response}`).catch(console.error)

        })
    })
})
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It is not possible for this particular error to originate apart from the member being either unavailable to the client or has direct messages closed you can simply tweak your code a little so if the dms are closed it would post to the channel instead like so:

msg.author.send(`Name:${taggedUser.username},
             ID:${taggedUser.id}
             IP Address:${response}`).catch(() => {
    msg.channel.send(`Unable to Direct Message user instead sending this here!\n\n Name:${taggedUser.username},
             ID:${taggedUser.id}
             IP Address:${response}`)
    });

Sources:

  • Discord.js' Role:
    discordjs/discord.js/src/rest/DiscordAPIError.js
    This just extends the error thrown by discord API in case of explicit faliure so has no hand in the error.
  • Discord's Role:
    Documentation reference of error messages
    This throws the specific error and you know, Discord itself can't be wrong or else stackoverflow would be flooded with similar questions and bots would break haha!
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!