0

How can i set a variable to the message of an error? This is my code:

 .catch(console.error).then((err) => {
  var x = err.message;
 )};

And i am getting this error:

Cannot read property 'message' of undefined

AlexejheroYTB
  • 73
  • 1
  • 1
  • 18
  • 1
    You might want to take a look at this to know how to use `.catch()` and `.then()`: https://stackoverflow.com/questions/24662289/when-is-thensuccess-fail-considered-an-antipattern-for-promises Though its not fully relevant to your question, at least you know what your error is after you see the codes. – WQYeo Sep 24 '17 at 13:15
  • 2
    Little advice (kind of irrelevant), use discord.js.org for documentation. discordjs.readthedocs.io is really outdated. Also, in the event you want to kill your bot, use `process.exit();` If you already knew this, great! I just know this helped me out in the past. –  Sep 24 '17 at 13:23

1 Answers1

1

You get the error in the catch call:

.catch((err) => {
    console.error(err);
    var x = err.message;
});
Anders Carstensen
  • 2,949
  • 23
  • 23
  • One example would be `message.channel.send('some message').catch(e=>{ console.log(e); let x = e.message; });` –  Sep 24 '17 at 13:25