A SerenityJS plugin to create, manage, and send Discord webhooks easily in SerenityJS plugins. This plugin provides a simple interface to build rich messages with embeds, fields, avatars, usernames, and forum-style threads.
- Send messages via Discord webhooks.
- Fully customizable message content.
- Supports embeds with titles, descriptions, colors, authors, footers, images, thumbnails, and timestamps.
- Add multiple fields to embeds.
- Validation for URLs and message content before sending.
- Copy the
webhook-apiplugin folder into yourplugins/directory.
import { WebHook, Base } from "webhook-api";
WebHook.make(
"YOUR_WEBHOOK_URL",
Base.make()
.setContent("Hello from another plugin!")
.setUsername("MyBot")
).send();import { WebHook, Base, EmbedManager, Field, EmbedColors } from "webhook-api";
WebHook.make(
"YOUR_WEBHOOK_URL",
Base.make()
.setContent("Check out this embed!")
.setUsername("EmbedBot")
.addEmbed(
EmbedManager.make("Embed Title", "This is an embed description", EmbedColors.Green)
.addField(Field.make("Field Name", "Field Value", true))
.addField(Field.make("Another Field", "Value", false))
)
).send();The main body of the message.
Methods:
setContent(content: string): Set message content.setUsername(username: string): Set the webhook username.setAvatar(avatarUrl: string): Set the webhook avatar URL.setTextToSpeech(tts: boolean): Enable/disable TTS.addEmbed(embed: EmbedManager): Add an embed to the message.setForumTitle(title: string): Enable forum-style thread with a title.build(): Validate the message before sending.toJson(): Convert message to JSON for sending.
Build rich embeds with multiple properties.
Methods:
setTitle(title: string)setDescription(description: string)setColor(color: number)addField(field: Field)setAuthor(author: Author)setFooter(footer: Footer)setThumbnail(thumbnail: Thumbnail)setImage(image: Image)setTimestamp(timestamp: Timestamp)
Represents a name-value pair inside an embed.
make(name: string, value: string, inline?: boolean): Create a field.inlineindicates whether the field is displayed inline.
Handles sending the message to Discord.
Methods:
make(url: string, body: Base): Create a webhook instance.send(): Sends the webhook message.setBody(body: Base): Update the body of the webhook.
- All URLs (avatars, thumbnails, images) must be valid.
- Each message must have either content or at least one embed.
Base.build()ensures messages are valid before sending.- Multiple embeds and fields are supported.
- Supports TTS messages and forum-style threads.
import { WebHook, Base, EmbedManager, Field, EmbedColors } from "webhook-api";
const embed = EmbedManager.make("Full Embed", "This embed has everything!", EmbedColors.Blue)
.addField(Field.make("Inline Field", "Displayed inline", true))
.addField(Field.make("Block Field", "Displayed in its own line", false));
WebHook.make(
"YOUR_WEBHOOK_URL",
Base.make()
.setContent("A full-featured webhook!")
.setUsername("AdvancedBot")
.setAvatar("https://example.com/avatar.png")
.addEmbed(embed)
.setForumTitle("My Thread")
).send();