Appearance
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
| Name | Type | Optional | Description |
|---|---|---|---|
client | Client | No | |
data | any | No | API webhook from POST /channels/{id}/webhooks (has token) or GET /webhooks/{id} (no token) |
Properties
| Name | Type | Readonly | Optional | Description |
|---|---|---|---|---|
avatar | string | null | No | No | |
channelId | string | No | No | |
client | Client | Yes | No | |
guildId | string | Yes | No | |
id | string | Yes | No | |
name | string | No | No | |
token | string | null | Yes | No | Present only when webhook was created via createWebhook(); not returned when fetching. |
user | User | Yes | No | User 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:
| Name | Type | Optional | Description |
|---|---|---|---|
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:
| Name | Type | Optional | Description |
|---|---|---|---|
options | any | No | Fields 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:
| Name | Type | Optional | Description |
|---|---|---|---|
messageId | string | No | The ID of the message to edit |
options | APIWebhookEditMessageRequest | No | Fields to update (content, embeds, attachments) |
fetch() async
Fetch a webhook by ID using bot auth.
Returns: Promise<Webhook>
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
client | Client | No | The client instance |
webhookId | string | No | The webhook ID |
fromToken()
Create a Webhook instance from an ID and token (e.g. from a stored webhook URL).
Returns: Webhook
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
client | Client | No | The client instance |
webhookId | string | No | The webhook ID |
token | string | No | The webhook token (from createWebhook or stored) |
options | { channelId?: string; guildId?: string; name?: string; } | Yes | Optional 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:
| Name | Type | Optional | Description |
|---|---|---|---|
options | string | WebhookSendOptions | No | Text content or object with content, embeds, username, avatar_url, tts, files, attachments |
wait | boolean | Yes | If true, waits for the API and returns the created Message; otherwise returns void (204) |