https://github.com/gaurishhs/discord-webhooks-node
Easily send messages to discord channels via webhooks
https://github.com/gaurishhs/discord-webhooks-node
Last synced: 3 months ago
JSON representation
Easily send messages to discord channels via webhooks
- Host: GitHub
- URL: https://github.com/gaurishhs/discord-webhooks-node
- Owner: gaurishhs
- License: mit
- Created: 2022-11-17T16:26:41.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-11-18T16:08:20.000Z (over 2 years ago)
- Last Synced: 2025-02-28T10:27:59.205Z (3 months ago)
- Language: TypeScript
- Homepage: https://gaurishhs.github.io/discord-webhooks-node/
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Discord Webhooks
[](https://img.shields.io/npm/dw/discord-webhooks-node)
[](https://img.shields.io/github/license/gaurishhs/discord-webhooks-node)- [Installation](#installation)
- [Usage](#usage)
- [Basic Usage](#basic-usage)
- [Send files](#send-files)
- [Send embeds](#send-embeds)
- [Config](#config)
- [API](https://gaurishhs.github.io/discord-webhooks-node/)
- [License](#license)## Installation
```bash
npm install discord-webhooks-node
```## Usage
### Basic Usage
```ts
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
```ts
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:
```ts
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
```ts
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
```ts
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.