DiSky DiSky v5.0.0-b1

Posting through a webhook

guide

Post, edit and delete messages as a webhook, with a per-message name and avatar, in a channel or a thread.

webhooksmessagesbuilder

This page covers what a webhook client does once you have one: post a message, override its name and avatar for that message, keep the sent message to edit or delete it later, and post in a thread. You're assumed to have a webhook client in {_hook} and a bot named "my-bot" logged in.

How posting works

sends a text, an embed, a component or a message builder through the webhook. send and speak are the same effect under other names. Like post, it forgets the message it sent.

on message received seen by "my-bot":
    if discord content of event-message is "!announce":
        set {_b} to a new webhook builder named "Announcer" in event-channel
        await set {_hook} to the build result of {_b}
        make {_hook} post "Server restart in 5 minutes"
        make {_hook} post "Restarted" with username "Status" and avatar "https://example.com/up.png"

with username and and avatar change how the webhook appears for this message only; its own name and avatar stay as they are. A message builder given as content is used as a template: its content, embeds, attachments and components are sent, the rest of the builder is ignored.

effect webhook postWebhook Clientmake [the] [webhook] [client] %webhookclient% (post|send|speak) %string/embedbuilder/component/messageaction% [with [the] username %-string%] [[and] [with] [the] avatar [url] %-string%] [in [the] thread %-threadchannel%]Makes a webhook, or a webhook client built from a URL, post a message.since 5.0.0-a2

Keeping the sent message

and a new webhook message with embed %embedbuilder% through %webhookclient% create a webhook message builder. It follows the builder contract: nothing is sent until the build result of it is read under await, and that read returns the sent message.

on message received seen by "my-bot":
    if discord content of event-message is "!status":
        set {_m} to a new webhook message with content "Checking..." through {_hook}
        set webhook username of {_m} to "Status"
        await set {_sent} to the build result of {_m}
        edit webhook message {_sent} of {_hook} to show "All systems up"
expression resultWebhook Message Builder[the] (build|built) result of [the] %webhookmessageaction%Sends the message through the webhook and returns it. Requires 'await'.Messagesince 5.0.0-a2

Options

Every property below is write-only on the builder.

Property

Default

Accepted values

the webhook's name

any text

the webhook's avatar

an image URL

none, the webhook's channel

a thread of the webhook's channel

none

a thread id

the constructor's text

any text

the constructor's embed

an embed

none

file uploads

none

components

false

true, false

false

true, false

false

true, false

set {_m} to a new webhook message with content "Patch notes" through {_hook}
set webhook username of {_m} to "Changelog"
set webhook avatar url of {_m} to "https://example.com/log.png"
add (a new file upload from file "plugins/notes.txt") to attachments of {_m}
set suppressed notifications of {_m} to true
await set {_sent} to the build result of {_m}

Editing and deleting

and take the sent message or its id. A webhook can only edit and delete its own messages, and a client built from a URL works the same way as the webhook it points to.

on message received seen by "my-bot":
    if discord content of event-message is "!cleanup":
        set {_m} to a new webhook message with content "temporary" through {_hook}
        await set {_sent} to the build result of {_m}
        delete webhook message (discord id of {_sent}) of {_hook}
effect webhook editCore · Effectsedit [the] webhook message %string/message% of [the] [webhook] [client] %webhookclient% (with|to show) %string/embedbuilder/component/messageaction% [in [the] thread %-threadchannel%]Edits a message that was sent through a webhook, by its message or its id.since 5.0.0-a2

Threads

A webhook posts in its own channel, or in a thread of that channel. Add in thread %threadchannel% to any of the three effects, or set webhook thread on the builder. A message sent in a thread must be edited and deleted with the same in thread, or Discord answers that the message does not exist.

on message received seen by "my-bot":
    if discord content of event-message is "!thread-post":
        set {_tb} to a new thread builder named "Logs" from event-message
        await set {_thread} to the build result of {_tb}
        make {_hook} post "first entry" in thread {_thread}

Errors you may see

Message (console)

Cause

Fix

this message has no content, no embed, no attachment and no component; Discord refuses an empty message

A webhook message builder was built with nothing to send

Set a content, an embed, an attachment or a component

[10008] Unknown Message

The message was not sent by this webhook, or it lives in a thread and in thread is missing

Edit through the webhook that sent it, naming the thread

[10015] Unknown Webhook

The webhook was deleted

Create or retrieve a new one

Webhook Message Builder type 14 syntaxes A message a webhook has not sent yet: configure it, then send it with 'the build result of'. Nothing reaches Discord until then, and the result is the sent message itself, which can later be edited or deleted through the same webhook.
Was this page helpful?
An unhandled error has occurred. Reload 🗙

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.