如何设置 if 语句,如果用户有 DM 阻止机器人发送错误

How to setup an if statment, so if the user has DMs blocked the bot sends an error

在我的 discord 机器人中,有一个 /help 命令 DMs 用户命令列表。我的问题是,有些用户的私信被锁定了。我想要这样,如果用户阻止了 DM,则机器人只会在频道中发送消息。我试过使用 try catch 块,但没有任何反应。这是代码:

// 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"
}

总结一下:

=> /help 命令有效 => 如果用户阻止了他们的 DM,他们将不会收到机器人发送的消息。 => 如果出现错误,我该怎么做才能让机器人只在执行命令的通道中发送消息?

另外,如果我拼错了什么请告诉我.... #PrepearingForGCSEs

这段代码应该可以像您描述的那样工作。我还合并了一个嵌入数组并使用循环来提高效率。

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();  
    });
  }
}