Discord js Add reaction to a bot message

ZaraaKai picture ZaraaKai · May 31, 2017 · Viewed 42.2k times · Source

I've been created my own discord bot but i have this error for this code:

It's send a message to the channel and add reaction, and in my console i have this error:

(node:11728) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): DiscordAPIError: Unknown Message
(node:11728) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:11728) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): DiscordAPIError: Unknown Message

Answer

Nevosis picture Nevosis · May 31, 2017

Those aren't error, those are warning. As it is said, you don't check when your promise is rejected. You should use .catch() after .then() in case it get rejected.

https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/Promise/catch

Try :

message.channel.send(":apple:***SONDAGE :apple:\n "+choix1+" ou "+""+choix2+"***")
            .then(function (message) {
              message.react("👍")
              message.react("👎")
              message.pin()
              message.delete()
            }).catch(function() {
              //Something
             });