Discord.js: Sending a DM to a user throws an exception even if the message is sent successfully.

Created on 3 Jul 2020  Â·  3Comments  Â·  Source: discordjs/discord.js

Please describe the problem you are having in as much detail as possible:
I was testing DM functionality of the bot, and I tried to send myself a message via the "message" event.
The message sent to me without any problem on Discord end; however, it tries to send the same message for a second time and discord.js throws an error.
Include a reproducible code sample here, if possible:

var token= "<your bot token>", Discord = require("discord.js");
var discordClient= new Discord.Client();
discordClient.on("message", message => {
    message.author.createDM()
        .then(dm=>dm.send("Hey!")
}).login(token);

//Assume someone sent an message.
//UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send messages to this user
//  at RequestHandler.execute (<app folder>\node_modules\discord.js\src\rest\RequestHandler.js:170:25)
//  at processTicksAndRejections (internal/process/task_queues.js:97:5)

Further details:

  • discord.js version: 12.2.0
  • Node.js version: v14.4.0
  • Operating system: Windows 10 x64 Build: 1909 (Education version)
  • Priority this issue should have – please be realistic and elaborate if possible: Low
    but it's annoying to see.

- [ ] I have also tested the issue on latest master, commit hash:

Currently testing it on the latest commit, will update if it's fixed on a later commit or not.

unverified bug

Most helpful comment

The bot tries to send a message to itself in a DM, and it can't.

Why?:

  1. You send a message
  2. Message event is triggered (author: you, channel: in server)
  3. Bot sends you a message
  4. Message event is triggered (author: bot, channel: dm with you)
  5. Bot tries to send a message to a DM with itself, which is not possible.

All 3 comments

The bot tries to send a message to itself in a DM, and it can't.

Why?:

  1. You send a message
  2. Message event is triggered (author: you, channel: in server)
  3. Bot sends you a message
  4. Message event is triggered (author: bot, channel: dm with you)
  5. Bot tries to send a message to a DM with itself, which is not possible.

Hold up, I forgot to ignore the message if the bot sent the message 🤦

Yep that's the case, bot tried to open a DM chat with itself and somehow sent another message to the first dm channel. Have a nice day!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  Â·  3Comments

ghost picture ghost  Â·  3Comments

iCrawl picture iCrawl  Â·  3Comments

xCuzImPro picture xCuzImPro  Â·  3Comments

Brawaru picture Brawaru  Â·  3Comments