Simple convenience library for type-safe interaction with discord's Webhook API.
Includes a functional API for componentsV2 objects.
Install:
pnpm install dschook # or npm, bun, ...Use:
import { Webhook } from "dschook";
const hook = new Webhook("https://discord.com/api/webhooks/...");Sending regular text messages:
hook.send_text("Hello!");Sending ComponentsV2 (via the static Webhook.components and Webhook.colors APIs):
const { container, text } = Webhook.components;
const { rgb } = Webhook.colors;
hook.send_components(
text("Hello"),
container(rgb(100, 0, 0), false, [
text("I'm stuck inside a red-lined container!")
])
);Sending polls:
hook.send_poll(
"What's your favourite color?",
["Red", "Orange", "Yellow", { text: "green", emoji_name: "💚" }],
// Optional arguments: poll duration in hours and whether to allow selecting multiple options
5, true
);Sending 1-10 embed objects:
hook.send_embed({
color: Webhook.colors.rgb(100, 0, 0)
author: { name: "github user" },
fields: [
{ name: "foo", value: "bar" }
]
});(Note: While sending embeds is supported, using message components is the recommended modern approach.)
Sending multiple content types in one message:
hook.send({
text: "foo",
embeds: [/* ... */]
});Sending messages as a user:
hook.as_user("Charles", /* optional */ "avatarURL").sendText("My name is Charles");Sending messages in a thread (the webhook must be in a forum to work):
hook.in_thread("Good morning thread").sendComponents(
text("Good morning!")
);Sending messages with text-to-speech:
hook.with_tts().send_text("boo!");These modifiers can be stacked.
PRs welcome!
- Uploading attachments and/or files
- Editing and deleting uploaded webhooks