Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

discord-webhook-node

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

discord-webhook-node

Allows for easy webhook sending through discord's webhook API

  • 1.1.2
  • npm
  • Socket score

Version published
Weekly downloads
4.9K
decreased by-11.19%
Maintainers
1
Weekly downloads
 
Created
Source

Discord Webhook sending

version npm

How to use

Basic use:

const webhook = require('discord-webhook-node');
const hook = new webhook.Webhook("YOUR WEBHOOK URL");

hook.send("Hello there!");

Custom embeds:

const webhook = require('discord-webhook-node');
const hook = new webhook.Webhook("YOUR WEBHOOK URL");

const embed = new webhook.messageBuilder()
.setTitle('My title here')
.setAuthor('Author here', 'https://cdn.discordapp.com/embed/avatars/0.png', 'https://www.google.com')
.setURL('https://www.google.com')
.addField('First field', 'this is inline', true)
.addField('Second field', 'this is not inline')
.setColor(7785669)
.setThumbnail('https://cdn.discordapp.com/embed/avatars/0.png')
.setDescription('Oh look a description :)')
.setImage('https://cdn.discordapp.com/embed/avatars/0.png')
.setFooter('Hey its a footer', 'https://cdn.discordapp.com/embed/avatars/0.png')
.setTimestamp();

hook.send(embed);

Keep in mind that the custom embed method setColor takes in a decimal color. You can convert hex colors to decimal using this website here: https://convertingcolors.com

Preset messages:

const webhook = require('discord-webhook-node');
const hook = new webhook.Webhook('YOUR WEBHOOK URL');

//Sends an information message
hook.info('**Information hook**', 'Information field title here', 'Information field value here');

//Sends a success message
hook.success('**Success hook**', 'Success field title here', 'Success field value here');

//Sends an error message
hook.error('**Error hook**', 'Error field title here', 'Error field value here');

discord-webhook-node is a promise based library, which means you can use .catch, .then, and await, although if successful will not return any values. For example:

const webhook = require('discord-webhook-node');
const hook = new webhook.Webhook("YOUR WEBHOOK URL");

hook.send("Hello there!")
.then(() => console.log('Sent webhook successfully!'))
.catch(err => console.log(err.message));

or using async:

const webhook = require('discord-webhook-node');
const hook = new webhook.Webhook("YOUR WEBHOOK URL");

(async () => {
    try {
        await hook.send('Hello there!');
        console.log('Successfully sent webhook!');
    }
    catch(e){
        console.log(e.message);
    };
})();

Custom settings:

const webhook = require('discord-webhook-node');
const hook = new webhook.Webhook({
    url: "YOUR WEBHOOK URL",
    //If throwErrors is set to false, no errors will be thrown if there is an error sending
    throwErrors: false,
    //retryOnLimit gives you the option to not attempt to send the message again if rate limited
    retryOnLimit: false
});

Installation

npm install discord-webhook-node

License

MIT

Keywords

FAQs

Package last updated on 27 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc