Socket
Book a DemoInstallSign in
Socket

discord-webhooks-node

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

discord-webhooks-node

[![Downloads](https://img.shields.io/npm/dw/discord-webhooks-node)](https://img.shields.io/npm/dw/discord-webhooks-node) [![License](https://img.shields.io/github/license/gaurishhs/discord-webhooks-node)](https://img.shields.io/github/license/gaurishhs/di

1.0.4
latest
Source
npmnpm
Version published
Weekly downloads
8
100%
Maintainers
1
Weekly downloads
 
Created
Source

Discord Webhooks

Downloads License

Installation

npm install discord-webhooks-node

Usage

Basic Usage

import { Webhook } from 'discord-webhooks-node';

const webhook = new Webhook({
    url: 'WEBHOOK_URL',
});

webhook.execute({
    content: 'Hello world!',
}).then(() => console.log('Sent!')).catch((err) => console.error('Failed! ', err));

Send files

import { Webhook } from 'discord-webhooks-node';

const webhook = new Webhook({
    url: 'WEBHOOK_URL',
});

webhook.execute({
    content: 'Hello world!',
    files: [
        {
            name: 'test.txt',
            file: Buffer.from('Hello world!'),
        },
    ],
}).then(() => console.log('Sent!')).catch((err) => console.error('Failed! ', err));

As an embed attachment:

import { readFileSync } from 'fs';
import { Embed, Webhook } from 'discord-webhooks-node';

const webhook = new Webhook({
    url: 'WEBHOOK_URL',
});

webhook.execute({
    content: 'Hello world!',
    embeds: [new Embed().setTitle('Hello world!').setDescription('This is a test embed.').setImage('attachment://test.jpeg').toJSON()],
    files: [
        {
            name: 'test.jpeg',
            // Read test.jpeg from the current directory
            file: readFileSync(__dirname + '/test.jpeg'),
        },
    ],
}).then(() => console.log('Sent!')).catch((err) => console.error('Failed! ', err));

Send embeds

import { readFileSync } from 'fs';
import { Button, Embed, MessageBuilder, Webhook } from '../src';

const webhook = new Webhook({
    url: 'WEBHOOK_URL',
});

const msg = new MessageBuilder('Hello World!')
.addEmbed(
    new Embed()
    .setTitle('Hello World!')
    .setDescription('This is a test embed!')
    .setColor('#ff0000')
    .setFooter('https://discord.com', 'This is a test footer!')
    .setTimestamp()
    .setThumbnail('https://cdn.discordapp.com/embed/avatars/0.png')
    .setAuthor('Test Author', 'https://discord.com', 'https://cdn.discordapp.com/embed/avatars/0.png')
    .addField('Test Field', 'This is a test field!', false)
)
.addComponent(new Button().setLabel('Test Button').setStyle(1).setURL('https://discord.com'));
 
webhook.execute(msg.toJSON()).then(() => console.log('Sent!')).catch((err) => console.error('Failed! ', err));

Config

import { Webhook } from 'discord-webhooks-node';

const webhook = new Webhook({
    url: 'WEBHOOK_URL',
})

webhook.setUsername('Test User');
webhook.setAvatar('https://cdn.discordapp.com/embed/avatars/0.png');

License

  • This project is MIT Licensed. Read the license file for more information.

Keywords

webhooks

FAQs

Package last updated on 18 Nov 2022

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.