discord-hookr
v1.0.0
Published
A simple yet powerful TypeScript library for working with Discord webhooks
Downloads
10
Maintainers
Readme
Discord Hooker
A simple yet powerful TypeScript library for working with Discord webhooks. This library provides a fluent interface for creating and managing Discord webhook messages with support for all Discord webhook features.
Features
- Send, edit, fetch, and delete webhook messages
- Support for embeds, components, and message flags
- Rich builder classes for embeds, buttons, select menus, and more
- Support for thread messages
- Modern TypeScript API with full type support
Installation
npm install discord-hookerBasic Usage
import { Webhook } from 'discord-hooker';
// Create a webhook instance
const webhook = new Webhook(
new URL('https://discord.com/api/webhooks/your-webhook-id/your-webhook-token')
);
// Send a simple message
await webhook.send({
content: 'Hello, Discord!',
});
// Send a message with an embed
await webhook.send({
content: 'Check out this embed:',
embeds: [
{
title: 'My Embed',
description: 'This is an embedded message',
color: 0x00ff00,
},
],
});Using Message Flags
Discord webhooks support message flags that can modify how messages are displayed. This library provides a MessageFlags enum and a MessageFlagsBitField builder for working with message flags.
Available Message Flags
SuppressEmbeds: Prevents links from creating embedsSuppressNotifications: Prevents notifications from being sentEphemeral: Makes the message only visible to the user who triggered the interaction- And more...
Using Message Flags Directly
import { MessageFlags, Webhook } from 'discord-hooker';
const webhook = new Webhook(new URL('your-webhook-url'));
// Send a message with the SuppressEmbeds flag
await webhook.send({
content: 'This message has suppressed embeds',
flags: MessageFlags.SuppressEmbeds,
});Using the MessageFlagsBitField Builder
The MessageFlagsBitField builder provides a fluent interface for combining multiple message flags:
import { MessageFlags, MessageFlagsBitField, Webhook } from 'discord-hooker';
const webhook = new Webhook(new URL('your-webhook-url'));
// Create a message flags bitfield
const flags = new MessageFlagsBitField()
.add(MessageFlags.SuppressEmbeds)
.add(MessageFlags.SuppressNotifications);
// Send a message with multiple flags
await webhook.send({
content: 'This message has multiple flags',
flags: flags.valueOf(), // Convert to a number
});Using Builders
The library provides builders for creating complex message components:
import {
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
EmbedBuilder,
Webhook,
} from 'discord-hooker';
const webhook = new Webhook(new URL('your-webhook-url'));
// Create an embed
const embed = new EmbedBuilder()
.setTitle('Interactive Message')
.setDescription('Click the buttons below')
.setColor(0x3498db);
// Create buttons
const actionRow = new ActionRowBuilder().addComponents(
new ButtonBuilder().setCustomId('button_1').setLabel('Click Me').setStyle(ButtonStyle.Primary),
new ButtonBuilder()
.setURL('https://discord.com')
.setLabel('Visit Discord')
.setStyle(ButtonStyle.Link)
);
// Send the message
await webhook.send({
embeds: [embed.toJSON()],
components: [actionRow.toJSON()],
});License
MIT
