index.js
// Function to send event to Discord's Incoming Webhook
Function to send event to Discord's Incoming Webhook
Function to send event to Discord ' s Incoming Webhook
function sendToDiscord(message) {
  var description = message.description;
  if (!conf.discord_url) {
    return console.error("There is no Discord URL set, please set the Discord URL: 'pm2 set pm2-discord:discord_url https://[discord_url]'");
  }
  var payload = {
    "content" : description
  };
  var options = {
    method: 'post',
    body: payload,
    json: true,
    url: conf.discord_url
  };
  request(options, function(err, res, body) {
    if (err) {
      return console.error(err);
    }
    if (res.statusCode !== 204) {
      console.error("Error occured during the request to the Discord webhook");
      console.error(body)
    }
  });
}
function sendToDiscord ( message ) { var description = message . description ; if ( ! conf . discord_url ) { return console . error ( "There is no Discord URL set, please set the Discord URL: 'pm2 set pm2-discord:discord_url https://[discord_url]'" ) ; } var payload = { "content" : description } ; var options = { method : 'post' , body : payload , json : true , url : conf . discord_url } ; request ( options , function ( err , res , body ) { if ( err ) { return console . error ( err ) ; } if ( res . statusCode !== 204 ) { console . error ( "Error occured during the request to the Discord webhook" ) ; console . error ( body ) } } ) ; }
Function to send event to Discord's Incoming Webhook
Function to send event to Discord ' s Incoming Webhook
// If a Discord URL is not set, we do not want to continue and nofify the user that it needs to be set // The JSON payload to send to the Webhook // Options for the post request // Finally, make the post request to the Discord Incoming Webhook /* A successful POST to Discord's webhook responds with a 204 NO CONTENT */