@glitch452/discord-webhook
v2.1.8
Published
Allows for easy webhook sending through discord's webhook API
Readme
Discord Webhook
Table of Contents
What's New
Check out the GitHub Releases page for the latest release notes.
Install
npm install @glitch452/discord-webhookExamples
Basic usage
import { MessageBuilder, Webhook } from '@glitch452/discord-webhook';
const hook = new Webhook('<YOUR_WEBHOOK_URL>');
hook.send('Hello there!');Using the MessageBuilder to set other message parameters
import { MessageBuilder, Webhook } from '@glitch452/discord-webhook';
const message = new MessageBuilder('Hello there!')
.setUsername('Bot Name')
.setAvatarUrl('https://cdn.discordapp.com/embed/avatars/0.png');
const hook = new Webhook('<YOUR_WEBHOOK_URL>');
hook.send(message);Adding a custom Embed to the message
import { EmbedBuilder, MessageBuilder, Webhook } from '@glitch452/discord-webhook';
const hook = new Webhook('<YOUR_WEBHOOK_URL>');
const embed = new EmbedBuilder()
.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('#00b0f4')
.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();
const message = new MessageBuilder().addEmbed(embed);
hook.send(message);Keep in mind that the custom embed method setColor takes in a decimal color or a hex color (pure black and white hex
colors will be inaccurate). You can convert hex colors to decimal using this website here:
https://convertingcolors.com
Sending files
import { MessageBuilder, Webhook } from '@glitch452/discord-webhook';
const hook = new Webhook('<YOUR_WEBHOOK_URL>');
const message = new MessageBuilder().addFile('../yourFileName.png');
hook.send(message);Preset messages
import { Webhook } from '@glitch452/discord-webhook';
const hook = new 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 warning message
hook.warning('**Warning hook**', 'Warning field title here', 'Warning field value here');
// Sends an error message
hook.error('**Error hook**', 'Error field title here', 'Error field value here');Custom settings
import { Webhook } from '@glitch452/discord-webhook';
const hook = new 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,
});License
The scripts and documentation in this project are released under the MIT License as defined by the Open Source Initiative.
