Skip to content

Webhook

Package: @erinjs/core

Represents a Discord/erin.js webhook. Supports creating, fetching, sending, and deleting. The token is only available when the webhook was created; fetched webhooks cannot send messages.

Constructor

NameTypeOptionalDescription
clientClientNo
dataanyNoAPI webhook from POST /channels/{id}/webhooks (has token) or GET /webhooks/{id} (no token)

Properties

NameTypeReadonlyOptionalDescription
avatarstring | nullNoNo
channelIdstringNoNo
clientClientYesNo
guildIdstringYesNo
idstringYesNo
namestringNoNo
tokenstring | nullYesNoPresent only when webhook was created via createWebhook(); not returned when fetching.
userUserYesNoUser who created the webhook.

Methods

avatarURL()

Get the URL for this webhook's avatar. Returns null if the webhook has no custom avatar.

Returns: string | null

Parameters:

NameTypeOptionalDescription
options{ size?: number; extension?: string; }Yes

delete() async

Delete this webhook. Requires bot token with Manage Webhooks permission.

Returns: Promise<void>

Parameters:

None


edit() async

Edit this webhook. With token: name and avatar only. Without token (bot auth): name, avatar, and channel_id.

Returns: Promise<Webhook>

Parameters:

NameTypeOptionalDescription
optionsanyNoFields to update (name, avatar, channel_id when using bot auth)

editMessage() async

Edit a message previously sent by this webhook. Requires the webhook token.

Returns: Promise<Message>

Parameters:

NameTypeOptionalDescription
messageIdstringNoThe ID of the message to edit
optionsAPIWebhookEditMessageRequestNoFields to update (content, embeds, attachments)

fetch() async

Fetch a webhook by ID using bot auth.

Returns: Promise<Webhook>

Parameters:

NameTypeOptionalDescription
clientClientNoThe client instance
webhookIdstringNoThe webhook ID

fromToken()

Create a Webhook instance from an ID and token (e.g. from a stored webhook URL).

Returns: Webhook

Parameters:

NameTypeOptionalDescription
clientClientNoThe client instance
webhookIdstringNoThe webhook ID
tokenstringNoThe webhook token (from createWebhook or stored)
options{ channelId?: string; guildId?: string; name?: string; }YesOptional channelId, guildId, name for display

send() async

Send a message via this webhook. Requires the webhook token (only present when created, not when fetched).

Returns: Promise<Message | undefined>

Parameters:

NameTypeOptionalDescription
optionsstring | WebhookSendOptionsNoText content or object with content, embeds, username, avatar_url, tts, files, attachments
waitbooleanYesIf true, waits for the API and returns the created Message; otherwise returns void (204)

Released under the Apache-2.0 License.