Discord Webhook sending
Installation
npm install discord-webhook-node
or yarn add discord-webhook-node
Examples
Basic use
const Webhook = ;const hook = "YOUR WEBHOOK URL"; const IMAGE_URL = 'https://homepages.cae.wisc.edu/~ece533/images/airplane.png';hook;hook; hook;
Custom embeds
const Webhook MessageBuilder = ;const hook = "YOUR WEBHOOK URL"; const embed = ; hook;
Keep in mind that the custom embed method setColor
takes in a decimal color/a hex color (pure black and white hex colors will be innacurate). You can convert hex colors to decimal using this website here: https://convertingcolors.com
Sending files
const Webhook = ;const hook = 'YOUR WEBHOOK URL'; hook;
Preset messages
const Webhook = ;const hook = 'YOUR WEBHOOK URL'; //Sends an information messagehook; //Sends a success messagehook; //Sends an warning messagehook; //Sends an error messagehook;
Custom settings
const Webhook = ;const hook = 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; hook; //Overrides the default webhook usernamehook; //Overrides the default webhook avatar
Notes
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 = ;const hook = "YOUR WEBHOOK URL"; hook;
or using async:
const Webhook = ;const hook = "YOUR WEBHOOK URL"; async { try await hook; console; catche console; ;};
By default, it will handle Discord's rate limiting, and if there is an error sending the message (other than rate limiting), an error will be thrown. You can change these options with the custom settings options below.
API
Webhook - class
Constructor
- options (optional) : object
- throwErrors (optional) : boolean
- retryOnLimit (optional) : boolean
Methods
- setUsername(username : string) returns this
- setAvatar(avatarURL : string (image url)) returns this
- async sendFile(filePath : string)
- async send(payload : string/MessageBuilder)
- async info(title : string, fieldName (optional) : string, fieldValue (optional) : string, inline (optional) : boolean)
- async success(title : string, fieldName (optional) : string, fieldValue (optional) : string, inline (optional) : boolean)
- async warning(title : string, fieldName (optional) : string, fieldValue (optional) : string, inline (optional) : boolean)
- async error(title : string, fieldName (optional) : string, fieldValue (optional) : string, inline (optional) : boolean)
MessageBuilder - class
Methods
- setText(text: string)
- setAuthor(author: string (text), authorImage (optional) : string (image url), authorUrl (optional) : string (link))
- setTitle(title: string)
- setURL(url: string)
- setThumbnail(thumbnail : string (image url))
- setImage(image : string (image url))
- setTimestamp(date (optional) number/date object)
- setColor(color : string/number (hex or decimal color))
- setDescription(description : string)
- addField(fieldName : string, fieldValue: string, inline (optional) : boolean)
- setFooter(footer : string, footerImage (optional) : string (image url))
License
MIT