discord-webhook-maker
v1.0.6
Published
Einfacher und chainable Builder fuer Discord-Webhooks mit voller Embed-Unterstuetzung.
Downloads
688
Maintainers
Readme
discord-webhook-maker
Ein einfacher, chainable Builder für Discord-Webhooks mit voller Embed-Unterstützung.
Null Dependencies, native fetch (Node 18+), TypeScript-Typen inklusive.
Installation
npm install discord-webhook-makerSchnellstart
const { Webhook, Embed, Colors } = require("discord-webhook-maker");
const embed = new Embed()
.setTitle("Server-Status")
.setDescription("Alle Systeme laufen normal.")
.setColor(Colors.GREEN)
.addField("CPU", "12%", true)
.addField("RAM", "1.4 GB / 8 GB", true)
.setTimestamp();
await new Webhook("https://discord.com/api/webhooks/...")
.setUsername("StatusBot")
.setContent("Stündlicher Report")
.addEmbed(embed)
.send();API
new Webhook(url)
| Methode | Beschreibung |
| ------------------------- | ---------------------------------------------- |
| .setContent(text) | Klartext-Nachricht (max. 2000 Zeichen) |
| .setUsername(name) | Überschreibt den Webhook-Namen |
| .setAvatar(url) | Überschreibt das Webhook-Avatar |
| .setTTS(boolean) | Aktiviert Text-to-Speech |
| .addEmbed(embed) | Hängt ein Embed an (max. 10 pro Nachricht) |
| .addEmbeds([...]) | Mehrere Embeds auf einmal |
| .clearEmbeds() | Entfernt alle Embeds |
| .toJSON() | Gibt die rohe Payload zurück |
| .send() | Sendet die Nachricht (Promise) |
new Embed()
| Methode | Beschreibung |
| ------------------------------------------------ | ----------------------------------------- |
| .setTitle(text) | Titel (max. 256 Zeichen) |
| .setDescription(text) | Beschreibung (max. 4096 Zeichen) |
| .setURL(url) | Link am Titel |
| .setColor(color) | Hex-String, Zahl oder Colors.*-Konstante|
| .setTimestamp(date?) | Default: new Date() |
| .setAuthor({ name, iconURL?, url? }) | Author-Block |
| .setFooter({ text, iconURL? }) | Footer-Block |
| .setThumbnail(url) | Kleines Bild oben rechts |
| .setImage(url) | Großes Bild unten |
| .addField(name, value, inline?) | Einzelnes Feld (max. 25 pro Embed) |
| .addFields([{ name, value, inline }]) | Mehrere Felder |
| .clearFields() | Entfernt alle Felder |
| .toJSON() | Gibt das rohe Embed-Objekt zurück |
Farben
const { Colors, hexToInt, rgbToInt } = require("discord-webhook-maker");
embed.setColor(Colors.BLURPLE); // Vordefinierte Konstante
embed.setColor("#5865F2"); // Hex-String
embed.setColor(0x5865f2); // Zahl
embed.setColor(rgbToInt(88, 101, 242));Verfügbare Konstanten: DEFAULT, WHITE, AQUA, GREEN, BLUE, YELLOW, PURPLE,
LUMINOUS_VIVID_PINK, GOLD, ORANGE, RED, GREY, NAVY, BLURPLE,
sowie DARK_*-Varianten.
Fehlerbehandlung
const { Webhook, WebhookException, ValidationException } = require("discord-webhook-maker");
try {
await hook.send();
} catch (err) {
if (err instanceof ValidationException) {
// Lokale Validierung schlug fehl (Limits, fehlende Felder, ...)
} else if (err instanceof WebhookException) {
// Discord antwortete mit einem Fehler
console.log(err.status, err.body);
}
}Komplettes Beispiel
const { Webhook, Embed, Colors } = require("discord-webhook-maker");
const embed = new Embed()
.setTitle("Neue Bestellung")
.setURL("https://shop.example.com/orders/42")
.setDescription("Eine neue Bestellung ist eingegangen.")
.setColor(Colors.BLURPLE)
.setAuthor({
name: "Shop-System",
iconURL: "https://i.imgur.com/AfFp7pu.png",
})
.setThumbnail("https://i.imgur.com/AfFp7pu.png")
.addFields([
{ name: "Kunde", value: "Max Mustermann", inline: true },
{ name: "Betrag", value: "49,99 €", inline: true },
{ name: "Artikel", value: "3" },
])
.setFooter({ text: "Order #42" })
.setTimestamp();
await new Webhook(process.env.DISCORD_WEBHOOK_URL)
.setUsername("Shop")
.addEmbed(embed)
.send();Limits (von Discord vorgegeben)
- Embeds pro Nachricht: 10
- Felder pro Embed: 25
- Titel: 256 Zeichen, Beschreibung: 4096 Zeichen
- Field-Name: 256, Field-Value: 1024
- Footer-Text: 2048, Author-Name: 256
- Klartext-Content: 2000 Zeichen
Der Builder validiert diese Limits clientseitig und wirft eine ValidationException,
bevor die Anfrage an Discord rausgeht.
Lizenz
MIT
