In my discord bot, there is a /help command that DMs the user a list of commands. My problem is, that some users have their DMs locked. I want it so that IF the user has DMs blocked, the bot will just send the messages in the channel. I've tried using a try catch block but nothing happens. Here's the code:

// defined embeds and stuff before this lime I am also  using a command handler 
/*try {
      message.channel.send(gettingcmds);//.then; message.edit(gotcmds);
      message.author.send({embed: modAdmin});
      message.author.send({embed: botcmds});
      message.author.send({embed: extras});
      message.author.send({embed: neededperms});
      message.channel.send(gotcmds); 

    }
    catch(e) {

          message.channel.send(problem);

    }   */

module.exports.help = {
  name: "help"
}

To summarise:

=> A /help command works => If the user has blocked their DMs, they will not receive the messages the bot will send. => If there is an error, how would I do it so the bot just sends the messages in the channel the command was executed in?

Also, if I spelt anything wrong please tell me.... #PrepearingForGCSEs

1 Answers

0
Community On Best Solutions

This code should work as you described. I also incorporate an array of the embeds and use a loop for efficiency.

let embeds = [modAdmin, botcmds, extras, neededperms];

try {
  for (let embed of embeds) message.author.send(embed);
  message.channel.send('Check your DMs!');
} catch(e) {
  for (let embed of embeds) {
    message.channel.send(embed)
    .catch(e => {
      return console.error();  
    });
  }
}