Discord js Add reaction to bot message

I created my own god discord, but I have this error for this code:

  		message.channel.send(":apple:***SONDAGE :apple:\n "+choix1+" ou "+""+choix2+"***")
    		.then(function (message) {
          message.react("πŸ‘")
          message.react("πŸ‘Ž")
       		message.pin()
          message.delete()
    			});
      

Run codeHide result


It sends a message to the channel and adds a 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
      

Run codeHide result


+3


source to share


1 answer


This is not an error, this is a warning. As said, you do not check when your promise is rejected. You should use .catch () after .then () in case of rejection.

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

      

+3


source







All Articles