Webhook clients
guideCreate a webhook in a channel, retrieve the existing ones, or build a client from a webhook URL.
This page covers the three ways to get something you can post through: creating a webhook, retrieving the webhooks a guild or channel already has, and building a client from a webhook URL. You're assumed to have a bot named "my-bot" logged in and to know the builder contract.
Creating a webhook
a new webhook builder named %string% in %guildchannel% prepares a webhook in a channel; like every builder, nothing exists on Discord until you read the build result of it under await. The bot needs Manage Webhooks in that channel.
on message received seen by "my-bot": if discord content of event-message is "!hook": set {_b} to a new webhook builder named "Announcer" in event-channel set webhook avatar of {_b} to "https://example.com/avatar.png" await set {_hook} to the build result of {_b} make {_hook} post "Hello from a fresh webhook"
webhook avatar is the only setter of the builder (an image URL or a local file path): the name and the channel are given to the constructor. A channel holds at most 15 webhooks; Discord refuses the build beyond that.
[a] new webhook builder [(named|with [the] name)] %string% in [the] [channel] %guildchannel%Creates a webhook builder for a channel. The webhook only exists once you read 'the build result of' it, which requires 'await'.Retrieving existing webhooks
webhooks of %guild% lists every webhook of a guild, and channel webhooks of %standardguildmessagechannel% the ones of a single channel. Both ask Discord, so both require await (see cache and await), and both need Manage Webhooks.
on message received seen by "my-bot": if discord content of event-message is "!hooks": await set {_hooks::*} to channel webhooks of event-channel loop {_hooks::*}: reply with "%name of loop-value% (%webhook type of loop-value%)"
[the] webhooks of %guild%All webhooks of the guild. Fetched online, so it requires 'await'.Building a client from a URL
a new webhook client from url %string% turns a webhook URL (the one Discord shows under Integrations → Webhooks → Copy Webhook URL) into a client. It needs no permission in the guild and the bot does not have to be in it: the bot only carries the HTTP requests. Without using bot, the only loaded bot is used.
options: hook-url: "https://discord.com/api/webhooks/123/abc" on message received seen by "my-bot": if discord content of event-message is "!url-hook": set {_client} to a new webhook client from url {@hook-url} using bot "my-bot" make {_client} post "Posted through a URL"
A client built this way can post, edit and delete its own messages, nothing else: it has no name, channel or owner to read, and destroy does not accept it.
Anyone holding a webhook URL, or its webhook token, can post through it. Keep it in an options: block or a file outside the scripts you share.
[a] new webhook client (from|with) [the] [webhook] url %string% [using [the] [bot] %-bot%]Creates a webhook client from a webhook URL (including its token).Webhook properties
A retrieved or created webhook exposes its Discord state. name, webhook avatar and webhook channel are writable and change the webhook on Discord; put await in front to wait for the change before the next line.
Property | Returns | Writable |
|---|---|---|
its display name | yes | |
its avatar URL | yes, from an image URL or a local file path | |
the channel it posts in | yes, to a text channel (moves it) | |
the URL a client can be built from | no | |
its secret token, none for a follower webhook | no | |
the member who created it, none if unknown | no | |
| no |
on message received seen by "my-bot": if discord content of event-message is "!rename-hooks": await set {_hooks::*} to channel webhooks of event-channel loop {_hooks::*}: await set name of loop-value to "Renamed"
Deleting a webhook
destroy deletes a webhook; every client built from its URL stops working at the same time.
on message received seen by "my-bot": if discord content of event-message is "!clear-hooks": await set {_hooks::*} to channel webhooks of event-channel loop {_hooks::*}: destroy loop-value
Errors you may see
Message (console) | Cause | Fix |
|---|---|---|
a webhook client needs a running bot to carry its requests |
| Log a bot in first, or add |
A Discord error naming Missing Permissions | The bot lacks Manage Webhooks in the channel | Grant it on the channel or the guild |
[10015] Unknown Webhook | The webhook was deleted, or the URL is wrong | Create a new webhook, or check the URL |