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:
Currently testing it on the latest commit, will update if it's fixed on a later commit or not.
The bot tries to send a message to itself in a DM, and it can't.
Why?:
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!
Most helpful comment
The bot tries to send a message to itself in a DM, and it can't.
Why?: