README
Webhook Builder
Sections
Installation
With NPM
$ npm install webhook-builder
With yarn
$ yarn add webhook-builder
Examples
Basic Use
/* ================================================================================= */
// Example //
/* ================================================================================= */
// Make sure you require the file.
// e.g: const { Webhook, MessageBuilder } = require("webhook-builder");
const webhook = new Webhook("your webhook url here");
// If you want to set a username and an icon/avatar for the webhook. Do this:
webhook.setWebhook({
username: "Your webhook username",
avatar_url: "Your avatar/icon URL",
});
// MessageBuilder (Object)
const mb = new MessageBuilder("Your content here", {
title: "Hello World!",
description: "This is a description",
color: "#fff",
});
// MessageBuilder (methods)
const mb = new MessageBuilder("Your content here")
.setTitle("Hello World!")
.setDescription("This is a description")
.setColor("#fff");
// Sending the webhook (Without promise prototypes)
webhook.send(mb);
// Sending the webhook (with promise prototypes)
webhook
.send(mb)
.then(() => {
console.log("The webhook has been sended successfully!");
})
.catch((err) => {
// Throws an error, if there is an error sending the webhook
throw new Error(err);
});
API
Webhook (Class)
Constructor:
- webhookURL: "String" | "URL"
Methods:
setWebhook
- data: "Object"
- username: "String"
- avatar_url: "String"
- data: "Object"
send
- content (optional): "String"
- embed (optional): "MessageBuilder"
(Content and embed parameters mustn't be null or empty)
EG:
// No. It's not gonna work webhook.send(null, null); // But this is valid webhook.send(null, mb); // And this webhook.send("Hello World!");
Message Builder (Class)
Constructor:
- Embed Object: "Object"
Methods:
setTitle
- title: "String"
setURL
- titleURL: "String" | "URL"
setDescription
- description: "String"
setColor
- color: "String" | "Number"
setAuthor
- authorOpts: "Object"
- name: "String"
- icon_url (optional): "String" | "URL"
- url (optional): "String" | "URL"
- authorOpts: "Object"
setThumbnail
- url: "String" | "URL"
setField
- footerOpts: "Object[]"
- name: "String"
- value: "String"
- inline (optional): "Boolean"
- footerOpts: "Object[]"
setFooter - footerText: "String" - footerIcon (optional): "String" | "URL"