Search code examples
loggingdiscorddiscord.js

DiscordJS v12 Cannot send messages to this user


let channelID = "951015988332232726";
let guildID = "911491194654175242";
client.on('message', (message) => {
  if(message.channel.type === 'dm'){
    let embed = new Discord.MessageEmbed()
    .setAuthor(client.guilds.cache.get(guildID).members.cache.get(message.author.id).displayName)
    .setThumbnail(message.author.displayAvatarURL())
    .setColor(ee.color)
    .setDescription(message.content)
    .setFooter(ee.footertext, ee.footericon);
    client.channels.cache.get(channelID).send(embed);

    let embed2 = new Discord.MessageEmbed()
    .setTitle('Thank You')
    .setColor(ee.color)
    .setDescription('Your response is being carefully recorded! <:check:947079937372872704>')
    .setFooter(ee.footertext, ee.footericon);
    message.author.send(embed2)
  }
});

I am creating a dm logging system but when the bot messages the user it gives the error DiscordAPIError: Cannot send messages to this user , although users are recieving the message. The Bot Replying Fine: https://prnt.sc/fwVMHzOMBaID The Bot Logging Fine: https://prnt.sc/hvce78pKaZtG The Error: https://prnt.sc/XAw7AV6i-2o6 I cannot figure out why


Solution

  • If the user has blocked the bot or doesn't allow DM (in general or in the server the bot is present) then it cannot work. You should try catch when sending the message.