Discordjs - Cannot send messages to this user

you cannot send messages to this user
discordjs send message to specific user
the server responded with error 50007 cannot send messages to this user
discordapierror: cannot send an empty message
discordjs send direct message
discord bot send direct message to user
discord js dm user
discord.js delete message

I am making a discord.js bot for a server I am in, but after attempting to send a DM to a user (who was just kicked, to notify them of it,) the bot won't send it at all and it will spit out an error,

"UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send messages to this user"

its out of control now, because it will work, I'll add a small something, it will STOP working (more or less expected) and then when I revert that addition it will spit out the error again.

Here is my code for the kick command

const Discord = require("discord.js");
const Client = new Discord.Client
const prefix = "m!"

module.exports.run = async(bot, message, args) => {
params = message.content.slice(prefix.length).trim().split(/ +/g);

command = args.shift().toLowerCase();

let memberKick = message.mentions.members.first();

let reasonKick = args.slice(1).join(" ");

if(message.member.roles.find("name", "MedaFrost Controller")) {
    var userReslv = message.guild.members.find("id", memberKick.id);
    let usericon = memberKick.displayAvatarURL;
    let botembed = new Discord.RichEmbed
    botembed.setDescription("❌ You Were Kicked From Roscord!");
    botembed.setColor("FF0000");
    botembed.setThumbnail(usericon);
    botembed.addField("Reason:", `${reasonKick}`);
    userReslv.send(botembed);
    memberKick.kick(reasonKick);
    message.channel.send("✅ " + `${memberKick}` + " was kicked! ✅")
} else {
    const userId = message.member.id
    message.channel.send("Sorry, " + `<@${userId}>` + ", but you do not have sufficient permissions!")
}
}

module.exports.help = {
name: "kickplayer",
description: "Kicks mentioned user."
}

Expanding from the comments: Maybe add a delay between the message and the actual kick?

Since your function is async, it's a good idea to write a small async delay helper:

const delay = (msec) => new Promise((resolve) => setTimeout(resolve, msec));

Now you can simply

userReslv.send(botembed);
await delay(100); // 100 msec = 0.1 seconds
memberKick.kick(reasonKick); 
// ...

Bot 'cannot send messages to this user' · Issue #4112 · discordjs , I have implemented a login system which prompts the user for a password via DMs. The user is in the server with my bot and when he tries to  I have implemented a login system which prompts the user for a password via DMs. The user is in the server with my bot and when he tries to execute the command in order for the bot to DM him with the prompt, the bot 'cannot send message


You should not be using delays or timers to solve this issue. Asynchronous calls in Discord.js return Promises, you should use those promises.

Promises are something that can basically turn your asynchronous workflow synchronous: when something happens -> do this.

This is the workflow:

  1. Send a message to a GuildMember
  2. Kick after the message is properly sent

Don't worry, they won't have time to react to the message as these actions will most likely happen instantaneously, thanks to Promises. There are no additional delays.

So basically:

GuildMember
  .createDM()
  .then((DMChannel) => {
    // We have now a channel ready.
    // Send the message.
    DMChannel
      .send(reason)
      .then(() => {
        // Message sent, time to kick.
        GuildMember.kick(reason);
      });
  });

Here's the referenced GuildMember

You can also catch, and you should. Catching happens when a Promise fails to execute the task it was assigned.

GuildMember
  .createDM()
  .then((DMChannel) => {
    // We have now a channel ready.
    // Send the message.
    DMChannel
      .send(reason)
      .then(() => {
        // Message sent, time to kick.
        GuildMember
          .kick(reason)
          .catch((e) => {
            console.log('Failed to kick!', e);
            // Do something else instead...
          });
      });
  });

(You can catch the message sending too, or creating the channel.)

Here you can learn more about Promises, which are an essential part of JavaScript: https://javascript.info/promise-basics

DiscordAPIError: Cannot send messages to this user · Issue #21 , This occurs when a user has turned off DMs from servers. Can be handled by adding a warning message for the user. Sponsor discordjs/discord.js Watch 180 Star 5.4k Fork 1.3k "DiscordAPIError: Cannot send messages to this user" - BUT the message was sent actually.


Errors, A guide made by the community of discord.js for its users. Example: DiscordAPIError: Cannot send an empty message. # Discord.js Errors. Discord.js Errors are errors which are thrown by the library itself, they can usually be  The current code that you have is used in an earlier version of the discord.js library, and the send function has been changed. To send a message, use this line: message.channel.send('My Message') If you get an error saying that message is not defined, make sure that you have put the line in your message event handler.


continuing AKX's response...

For anyone else struggling with this!

I put the const delay right above my var userReslv and I put the await delay(100) between my kick and message send. (There are probably many better ways to phrase that..)

My bot can log in but it cant send messages to the channel, sendMessage(channel, message). I get this error message when it tries to send a message to the server: Updated node.js and reinstalled discord.js. stuff then they demonized gun owners and wrongly banned servers and users so I stop  So right there you can tell that's your problem. Your bot is trying to send back and blank message, and discord is saying "hey, you can't do that". It's hard to see what exactly you're trying to do. But obviously, when you do words.append(args[i]) nothing is being added to your words array – 23k Nov 19 '17 at 22:08


Discord.js UnhandledPromiseRejectionWarning: DiscordAPIError , Discord.js UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot send an empty message. Post author if (user) { const member = message.guild.​member(user); try { const kickEmbed = new Discord.RichEmbed() . Make a new command that creates a welcome-messages channel, use guild.channels.cache.find(channel => channel.name === 'welcome-messages'), and send a message to that channel. This method will work fine in most cases, but will break if someone on that server decides to rename the channel.


DM discord bot >>JavaScript, Cannot send messages to this user at item.request.gen.end (c:\Users\Arthur\​Desktop\TICKET BOT\node_modules\discord.js\src\client\rest\  message.mentions.users returns a Collection (as previously mentioned), which you can loop over in a number of different ways. You'll be using .map() to loop here, since it allows you to easily collect and store data in a variable in order to send 1 final message in the end, as opposed to multiple.


UnhandledPromiseRejectionWarning: DiscordAPIError: Cannot , You can also send private messages to a user with a User object. This will send “​Hello!” as a private message to the original author of the received message. Hi @abysbit,. This post was moved to a different board that fits your topic of discussion a bit better. This means you’ll get better engagement on your post, and it keeps our community organized so users can more easily find information.