0
votes

I'm making a discord.js bot for a server. When i write !ayuda the bot won't send it at all and it will spit out an error

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

Here is my code for the help command

    switch (args[0]) { 
    case 'ayuda':
        const Embed = new RichEmbed()
        .setColor(0x06d6fe)
        .setFooter("© Capital Wolf", "https://i.imgur.com/0nn2u7q.gif" )
        .setTimestamp()
        .setImage("https://i.imgur.com/vU2PFJv.png")
        .setTitle("⚠ Has solicitado los comandos del Discord de **Capital Wolf** ⚠")
        .addField('!cache',
  "Muestra como borrar la cache de **Fivem**")
        .addField('!staff',
  "Muestra una lista de los miembros que pertenecen al **STAFF** de **Capital Wolf**")
        .addField('!invitacion',
  "Muestra una invitacion del servidor de Discord de **Capital Wolf**")
        .addField('!ip',
  "Muestra la ip del servidor de **Fivem** de **Capital Wolf**")
        message.member.send(Embed);
    break;
}
2
Does this answer your question? Discordjs - Cannot send messages to this userJakye

2 Answers

1
votes

Member can not allowed to send DM message to him from this server members. You can handle it with add .catch() block to message.member.send().

    switch (args[0]) { 
    case 'ayuda':
        const Embed = new RichEmbed()
        .setColor(0x06d6fe)
        .setFooter("© Capital Wolf", "https://i.imgur.com/0nn2u7q.gif" )
        .setTimestamp()
        .setImage("https://i.imgur.com/vU2PFJv.png")
        .setTitle("⚠ Has solicitado los comandos del Discord de **Capital Wolf** ⚠")
        .addField('!cache',
  "Muestra como borrar la cache de **Fivem**")
        .addField('!staff',
  "Muestra una lista de los miembros que pertenecen al **STAFF** de **Capital Wolf**")
        .addField('!invitacion',
  "Muestra una invitacion del servidor de Discord de **Capital Wolf**")
        .addField('!ip',
  "Muestra la ip del servidor de **Fivem** de **Capital Wolf**")
        message.member.send(Embed).catch(console.error)
    break;
}
0
votes

You could possibly be trying to send a message to a user that either has the bot blocked or has DM’s off for that server or entirely.

You could handle that by using a .catch() function

An example is the following..

//Your embed code could go here. 

message.author.send(putYourEmbedDeclarationHere).catch(error => {
    message.channel.send(`Something went wrong while I tried to send you a DM`)
})