Home > Net >  Discord.js, how to handle error sending private message to user with disabled privacy setting and re
Discord.js, how to handle error sending private message to user with disabled privacy setting and re

Time:02-28

Is there possible way to handle error that will return right back after error is triggered?

  if(command === 'test') {
    message.author.send('Dm Test').catch(error => {
      message.reply('I failed to send you a private message!')
      return;
    })
    //some code below, should not trigger after sending message error. 

The problem is that .catch will respond as last, how to handle this error and immediately return instead of running also code below? I tried to use try { but that didn't work.

message.author.send('           
  • Related