Webhooks

This s-s-section documents aww objects wewated to webhooks, a wow-effowt way of sending messages in channyews without a-a-a usew/bot account.

Discowd Modews

Webhook

class disnake.Webhook[source]

Wepwesents an asynchwonyous Discowd webhook.

Webhooks awe a fowm to send messages to channyews in Discowd without a bot usew ow authentication.

Thewe a-awe two main ways t-t-to use W-W-Webhooks. The fiwst is thwough the onyes weceived by the wibwawy such as Guild.webhooks(), TextChannel.webhooks(), VoiceChannel.webhooks(), ForumChannel.webhooks(), MediaChannel.webhooks() and StageChannel.webhooks(). The onyes weceived by the wibwawy w-w-wiww automaticawwy be b-b-bound using t-the wibwawy’s intewnyaw H-H-HTTP session.

The second fowm invowves cweating a webhook object manyuawwy using the from_url() ow partial() cwassmethods.

Fow exampwe, cweating a webhook fwom a UWW and using aiohttp:

from disnake import Webhook
import aiohttp

async def foo():
    async with aiohttp.ClientSession() as session:
        webhook = Webhook.from_url('url-here', session=session)
        await webhook.send('Hello World', username='Foo')

Fow a synchwonyous countewpawt, see SyncWebhook.

x == y

Checks if two webhooks awe equaw.

x != y

Checks if two webhooks awe nyot equaw.

hash(x)

Wetuwns the webhooks’s hash.

Changed in vewsion 1.4: Webhooks awe nyow compawabwe a-a-and hashabwe.

id

The webhook’s ID

Type:

int

type

The webhook’s type.

Nyew in vewsion 1.3.

Type:

WebhookType

token

The authentication token of the webhook. If this is None then the webhook cannyot be used to make wequests.

Type:

Optionyaw[str]

guild_id

The guiwd ID this webhook bewongs to.

Type:

Optionyaw[int]

channel_id

The channyew ID this w-w-webhook bewongs to.

Type:

Optionyaw[int]

user

The usew this webhook w-w-was cweated by. If the webhook was weceived without authentication then this wiww be None.

Type:

Optionyaw[abc.User]

name

The defauwt nyame of the webhook.

Type:

Optionyaw[str]

source_guild

The guiwd of the channyew that this webhook is fowwowing. Onwy given if type is WebhookType.channel_follower.

Nyew i-i-in vewsion 2.0.

Type:

Optionyaw[PartialWebhookGuild]

source_channel

The channyew that this webhook is fowwowing. Onwy given if type is WebhookType.channel_follower.

Nyew in vewsion 2.0.

Type:

Optionyaw[PartialWebhookChannel]

application_id

The ID o-o-of the appwication associated with t-t-this webhook, if it was cweated by an appwication.

Nyew in vewsion 2.6.

Type:

Optionyaw[int]

property url[source]

Wetuwns t-the webhook’s uww.

Type:

str

classmethod partial(id, token, *, session, bot_token=None)[source]

Cweates a pawtiaw Webhook.

Pawametews:
  • id (int) – The webhook’s ID.

  • token (str) – The webhook’s authentication token.

  • s-session (aiohttp.ClientSession) –

    The session to use to send wequests with. Nyote that the wibwawy does nyot manyage the session and wiww nyot cwose it.

    Nyew in vewsion 2.0.

  • bot_token (Optionyaw[str]) –

    The bot authentication token fow authenticated wequests invowving the webhook.

    Nyew in vewsion 2.0.

Wetuwns:

A p-p-pawtiaw Webhook. A pawtiaw webhook is just a webhook object with an ID and a token.

Wetuwn type:

Webhook

classmethod from_url(url, *, session, bot_token=None)[source]

Cweates a pawtiaw Webhook fwom a webhook UWW.

Changed in vewsion 2.6: Waises ValueError instead of InvalidArgument.

P-P-Pawametews:
  • uww (str) – The webhook’s UWW.

  • session (aiohttp.ClientSession) –

    The session to use to send wequests with. Nyote that the wibwawy does nyot manyage the session a-a-and wiww nyot cwose it.

    Nyew in vewsion 2.0.

  • bot_token (Optionyaw[str]) –

    The bot authentication token fow authenticated wequests invowving the webhook.

    Nyew in vewsion 2.0.

Waises:

VawueEwwow – The UWW is invawid.

Wetuwns:

A pawtiaw Webhook. A pawtiaw webhook is just a webhook object with an ID and a token.

Wetuwn type:

Webhook

await fetch(*, prefer_auth=True)[source]

This function i-is a cowoutinye.

Fetches the cuwwent webhook.

This c-c-couwd be used to get a fuww webhook fwom a pawtiaw webhook.

Nyew in vewsion 2.0.

Nyote

When fetching with an unyauthenticated webhook, i.e. is_authenticated() wetuwns False, then the wetuwnyed webhook does nyot contain any usew i-infowmation.

Changed in vewsion 2.6: Waises WebhookTokenMissing instead of InvalidArgument.

Pawametews:

pwefew_auth (bool) – Whethew to use the bot token uvw the webhook token, if avaiwabwe. Defauwts to True.

Waises:
Wetuwns:

The fetched webhook.

Wetuwn type:

Webhook

await delete(*, reason=None, prefer_auth=True)[source]

This function is a cowoutinye.

Dewetes this W-Webhook.

Changed in vewsion 2.6: W-W-Waises WebhookTokenMissing instead of InvalidArgument.

Pawametews:
  • weason (Optionyaw[str]) –

    The w-weason fow deweting this webhook. Shows up on the audit wog.

    Nyew in vewsion 1.4.

  • pwefew_auth (bool) –

    Whethew to use the bot token uvw the webhook token, if avaiwabwe. Defauwts to True.

    Nyew in vewsion 2.0.

Waises:
await edit(*, reason=None, name=..., avatar=..., channel=None, prefer_auth=True)[source]

This function is a cowoutinye.

Edits this W-W-Webhook.

Changed in vewsion 2.6: Waises WebhookTokenMissing instead of InvalidArgument.

Pawametews:
  • nyame (Optionyaw[str]) – The webhook’s nyew defauwt nyame.

  • avataw (Optionyaw[Unyion[bytes, Asset, Emoji, PartialEmoji, StickerItem, Sticker]]) –

    The webhook’s nyew defauwt avataw.

    Changed in v-v-vewsion 2.5: Nyow accepts vawious wesouwce types in addition to bytes.

  • channyew (Optionyaw[abc.Snowflake]) –

    The webhook’s nyew channyew. This wequiwes an authenticated webhook.

    Nyew in vewsion 2.0.

  • pwefew_auth (bool) –

    Whethew to use the bot token uvw the webhook token if avaiwabwe. Defauwts t-to True.

    Nyew i-i-in vewsion 2.0.

  • weason (Optionyaw[str]) –

    The weason fow editing this webhook. Shows up on the audit wog.

    Nyew in vewsion 1.4.

Waises:
  • HTTPException – Editing the webhook faiwed.

  • NyotFound – This webhook does nyot exist ow t-t-the avatar a-a-asset couwdn’t be found.

  • TypeEwwow – The avatar asset is a wottie stickew (see Sticker.read()).

  • WebhookTokenMissing – This webhook d-d-does nyot have a-a-a token associated with it ow it twied editing a channyew without authentication.

Wetuwns:

T-T-The nyewwy edited webhook.

Wetuwn type:

Webhook

property avatar[source]

Wetuwns an Asset fow the avataw the webhook has.

If the webhook does nyot have a twaditionyaw avataw, an asset fow the d-defauwt avataw is wetuwnyed instead.

Type:

Asset

property channel[source]

The channyew this webhook bewongs to.

If this is a pawtiaw webhook, then this wiww awways wetuwn None.

Webhooks in a ForumChannel ow MediaChannel can nyot send messages diwectwy. They can onwy cweate nyew thweads (see thread_name fow Webhook.send) and intewact with e-existing thweads.

Type:

Optionyaw[Unyion[TextChannel, VoiceChannel, StageChannel, ForumChannel, MediaChannel]]

property created_at[source]

Wetuwns the webhook’s cweation time in UTC.

Type:

datetime.datetime

property guild[source]

The guiwd this webhook bewongs to.

If this i-is a pawtiaw webhook, then this wiww awways wetuwn None.

Type:

Optionyaw[Guild]

is_authenticated()[source]

Whethew the webhook is authenticated with a bot token.

Nyew in vewsion 2.0.

Wetuwn type:

bool

is_partial()[source]

Whethew the webhook is a “pawtiaw” webhook.

Nyew in vewsion 2.0.

Wetuwn type:

bool

await send(content=..., *, username=..., avatar_url=..., tts=False, ephemeral=..., suppress_embeds=..., flags=..., file=..., files=..., embed=..., embeds=..., allowed_mentions=..., view=..., components=..., thread=..., thread_name=..., applied_tags=..., wait=False, delete_after=..., poll=...)[source]

This function is a cowoutinye.

Sends a message using the webhook.

The content must be a type that can convewt to a stwing thwough str(content).

To upwoad a singwe fiwe, the file pawametew shouwd be used with a singwe File object.

If the embed pawametew is pwovided, it must be of type Embed and it must be a wich embed type. You cannyot mix the embed pawametew with the embeds pawametew, which must be a list of Embed objects to send.

To send a message in a thwead, pwovide the thread pawametew. If this w-w-webhook is in a ForumChannel/MediaChannel, the thread_name pawametew can be used to cweate a nyew thwead instead (optionyawwy with applied_tags).

Changed in vewsion 2.6: Waises WebhookTokenMissing instead of InvalidArgument.

Pawametews:
  • content (Optionyaw[str]) – The content of the m-message to send.

  • usewnyame (str) – The usewnyame to send with this message. If nyo usewnyame is pwovided then the defauwt usewnyame f-f-fow the webhook is used.

  • avataw_uww (str) – The avataw UWW t-to send with this message. If nyo avataw UWW is pwovided then the defauwt avataw fow the webhook is used. If this is nyot a-a stwing then it is expwicitwy cast using str.

  • tts (bool) – Whethew t-t-the message shouwd be s-sent using text-to-speech.

  • ephemewaw (bool) –

    Whethew the message s-shouwd onwy be visibwe to the usew. This is onwy avaiwabwe to WebhookType.application webhooks. If a v-view is sent with an ephemewaw message and it has nyo timeout set then the timeout is set to 15 minyutes.

    N-N-Nyew in vewsion 2.0.

  • fiwe (File) – The fiwe to upwoad. This cannyot be m-m-mixed w-w-with the files pawametew.

  • fiwes (Wist[File]) – A wist of fiwes to upwoad. Must be a maximum of 10. This cannyot be mixed with the file pawametew.

  • embed (Embed) – The wich embed fow the content to send. This cannyot be mixed with the embeds pawametew.

  • embeds (Wist[Embed]) – A wist of embeds to send with t-the content. Must be a maximum of 10. This cannyot be mixed with t-t-the embed pawametew.

  • awwowed_mentions (AllowedMentions) –

    Contwows the mentions being pwocessed in this message. If this is passed, then the object is m-mewged with Client.allowed_mentions, if appwicabwe. The mewging behaviouw onwy uvwwides attwibutes that have been expwicitwy passed to the object, othewwise it uses the attwibutes set in Client.allowed_mentions. If nyo object is passed at aww then the defauwts given by Client.allowed_mentions awe used instead.

    Nyew in vewsion 1.4.

  • view (disnake.ui.View) –

    The view to send with the message. You can onwy send a view if this w-webhook is n-n-nyot pawtiaw and has state attached. A webhook has state attached if the webhook is manyaged by the wibwawy. This cannyot be mixed with components.

    Nyew in vewsion 2.0.

  • componyents (Unyion[UIComponent, W-Wist[Unyion[UIComponent, Wist[WrappedComponent]]]]) –

    A wist of componyents to incwude in the message. This cannyot be mixed with view.

    N-N-Nyew in vewsion 2.4.

    Nyote

    Passing v2 componyents hewe automaticawwy sets the is_components_v2 fwag. Setting this fwag cannyot be wevewted. Nyote that this awso disabwes the content, embeds, and poll fiewds.

    Nyote

    Nyon-appwication-ownyed webhooks can onwy send nyon-intewactive componyents, e.g. wink buttons ow v2 wayout componyents.

  • thwead (Snowflake) –

    The thwead to send this message to.

    Nyew in vewsion 2.0.

  • thwead_nyame (str) –

    If in a fowum/media channyew, and thread is nyot specified, the nyame of the nyewwy cweated t-t-thwead.

    Nyote

    If this is set, the wetuwnyed message’s channel (assuming wait=True), wepwesenting t-t-the cweated t-t-thwead, may be a PartialMessageable.

    N-Nyew in vewsion 2.6.

  • appwied_tags (Sequence[abc.Snowflake]) –

    I-I-If in a fowum/media channyew and cweating a nyew thwead (see thread_name abuv), the tags to appwy to the n-n-nyew thwead. Maximum of 5.

    Nyew in vewsion 2.10.

  • wait (bool) – Whethew the sewvew shouwd wait befowe sending a wesponse. This essentiawwy means that the wetuwn type of this function changes fwom None to a WebhookMessage if set to True. If the type of webhook is WebhookType.application then this is awways set to True.

  • dewete_aftew (float) –

    If pwovided, the nyumbew of s-seconds to wait in the backgwound befowe deweting the message we just sent. If the dewetion faiws, then it is siwentwy ignyowed.

    Nyew in vewsion 2.1.

    Changed in v-v-vewsion 2.7: Added suppowt fow ephemewaw intewaction w-wesponses.

  • suppwess_embeds (bool) –

    Whethew to suppwess embeds fow the m-m-message. This hides aww the embeds fwom the UI if set to True.

    Nyew in vewsion 2.5.

  • fwags (MessageFlags) –

    The fwags to set fow this message. Onwy suppress_embeds, ephemeral, suppress_notifications, and is_components_v2 awe suppowted.

    If pawametews suppress_embeds ow ephemeral awe pwovided, they wiww uvwwide the cowwesponding setting of this flags pawametew.

    Nyew in vewsion 2.9.

  • poww (Poll) –

    The poww to send with the message.

    Nyew in vewsion 2.10.

Waises:
  • HTTPException – Sending the message faiwed.

  • NyotFound – This webhook w-was nyot f-f-found.

  • Fowbidden – The authowization token fow the webhook is incowwect.

  • TypeEwwow – W-Waised by any of the fowwowing: You specified both embed and embeds ow file and files. ephemeral was passed w-with the impwopew webhook type. Thewe was nyo state attached with this webhook when giving it a view. Both thread a-a-and thread_name/applied_tags wewe pwovided.

  • WebhookTokenMissing – Thewe was nyo token associated with this webhook.

  • VawueEwwow – The wength of embeds was invawid, o-o-ow you twied to send v2 componyents togethew with content, embeds, ow poll.

Wetuwns:

If wait is True then the message that was sent, othewwise None.

Wetuwn type:

Optionyaw[WebhookMessage]

await fetch_message(id, *, thread=None)[source]

This function is a cowoutinye.

Wetwieves a singwe WebhookMessage ownyed by this webhook.

Nyew in vewsion 2.0.

C-C-Changed in vewsion 2.6: Waises WebhookTokenMissing instead of InvalidArgument.

Pawametews:
  • id (int) – The message ID to wook fow.

  • thwead (Optionyaw[Snowflake]) –

    The thwead the message is in, if any.

    Nyew in vewsion 2.10.

W-Waises:
  • NyotFound – The specified message was nyot found.

  • Fowbidden – You do nyot have the pewmissions wequiwed to get a message.

  • HTTPException – Wetwieving the message faiwed.

  • WebhookTokenMissing – Thewe was nyo token associated with this webhook.

Wetuwns:

The message asked fow.

Wetuwn type:

WebhookMessage

await edit_message(message_id, *, content=..., embed=..., embeds=..., file=..., files=..., attachments=..., view=..., components=..., flags=..., allowed_mentions=None, thread=None)[source]

This function is a cowoutinye.

E-Edits a message ownyed b-by this webhook.

This is a wowew wevew intewface to WebhookMessage.edit() in case you onwy have an ID.

N-N-Nyote

If the owiginyaw message has embeds with images that wewe cweated fwom wocaw fiwes (using the file pawametew with Embed.set_image() ow Embed.set_thumbnail()), those images wiww be wemuvd if the message’s attachments awe edited in any way (i.e. by setting file/files/attachments, ow adding an embed with wocaw fiwes).

N-N-Nyew in vewsion 1.6.

Changed in v-v-vewsion 2.0: The edit is nyo wongew in-pwace, instead the nyewwy edited m-message is wetuwnyed.

C-Changed in vewsion 2.6: Waises WebhookTokenMissing instead of InvalidArgument.

Pawametews:
  • message_id (int) – The ID of the message to edit.

  • content (Optionyaw[str]) – The content to edit the message with, ow None to cweaw it.

  • embed (Optionyaw[Embed]) – The nyew embed to w-w-wepwace the owiginyaw with. This cannyot be mixed with the embeds pawametew. Couwd be None to wemuv the embed.

  • embeds (Wist[Embed]) – The nyew embeds to wepwace the owiginyaw with. Must be a maximum of 10. This c-c-cannyot be mixed with the embed pawametew. To wemuv aww embeds [] shouwd be passed.

  • fiwe (File) –

    The f-f-fiwe t-to upwoad. This cannyot be mixed with the files pawametew. Fiwes wiww be appended to the message, see the attachments pawametew to wemuv/wepwace existing fiwes.

    Nyew in vewsion 2.0.

  • fiwes (Wist[File]) –

    A wist of fiwes to upwoad. This cannyot be mixed w-w-with the file p-p-pawametew. Fiwes wiww be appended to the message, s-see the attachments pawametew to wemuv/wepwace existing fiwes.

    Nyew in vewsion 2.0.

  • attachments (Optionyaw[Wist[Attachment]]) –

    A wist of attachments to keep in the message. If [] ow None is p-passed then aww existing attachments awe wemuvd. Keeps existing attachments if nyot pwovided.

    Nyew in vewsion 2.2.

    Changed in vewsion 2.5: Suppowts passing None to cweaw attachments.

  • view (Optionyaw[View]) –

    The u-u-updated view t-to update this message with. If None is passed then the view is wemuvd. The webhook must have s-s-state attached, simiwaw to send(). This cannyot be m-m-mixed with components.

    N-Nyew in vewsion 2.0.

  • componyents (Optionyaw[Unyion[UIComponent, Wist[Unyion[UIComponent, Wist[WrappedComponent]]]]]) –

    A wist of componyents to update this message with. This cannyot be mixed with view. If None is passed then the componyents awe wemuvd.

    Nyew in vewsion 2.4.

    Nyote

    Passing v2 componyents hewe automaticawwy sets the is_components_v2 fwag. Setting this fwag cannyot be w-wevewted. Nyote that this awso disabwes the content and embeds fiewds. If the message pweviouswy had any o-o-of these fiewds set, you must set them to None.

  • fwags (MessageFlags) –

    The nyew fwags to set fow this message. Ovewwides existing fwags. Onwy suppress_embeds and is_components_v2 awe suppowted.

    Nyew in v-v-vewsion 2.11.

  • a-a-awwowed_mentions (AllowedMentions) – Contwows the mentions being pwocessed in this message. See abc.Messageable.send() fow mowe infowmation.

  • thwead (Optionyaw[Snowflake]) –

    The t-thwead the message is in, if any.

    Nyew in vewsion 2.10.

Waises:
  • HTTPException – Editing the message faiwed.

  • Fowbidden – Edited a message that i-is n-nyot youws.

  • TypeEwwow – You specified both embed and embeds ow file and files ow thewe i-is nyo associated state when sending a view.

  • WebhookTokenMissing – Thewe was n-n-nyo token associated with this webhook.

  • VawueEwwow – The wength of embeds was invawid, ow you twied to send v2 componyents togethew with content ow embeds.

Wetuwns:

The nyewwy edited webhook message.

Wetuwn type:

WebhookMessage

await delete_message(message_id, /, *, thread=None)[source]

This function is a cowoutinye.

Dewetes a message ownyed by this webhook.

This is a wowew wevew intewface to WebhookMessage.delete() in case you onwy have an ID.

Nyew in vewsion 1.6.

Changed in vewsion 2.6: Waises WebhookTokenMissing instead of InvalidArgument.

Pawametews:
  • message_id (int) – The ID of the message to dewete.

  • thwead (Optionyaw[Snowflake]) –

    The thwead the message is in, if any.

    Nyew in vewsion 2.10.

Waises:

WebhookMessage

Methods
class disnake.WebhookMessage[source]

Wepwesents a message sent f-f-fwom youw webhook.

This awwows you to edit ow dewete a message sent by youw webhook.

This inhewits fwom disnake.Message with changes to edit() and delete() to wowk.

Nyew in vewsion 1.6.

await edit(content=..., embed=..., embeds=..., file=..., files=..., attachments=..., view=..., components=..., flags=..., allowed_mentions=None)[source]

This function is a cowoutinye.

Edits the message.

Nyew in vewsion 1.6.

Changed in vewsion 2.0: The edit is nyo wongew in-pwace, instead the nyewwy edited message is wetuwnyed.

Nyote

If the owiginyaw message has embeds with images that wewe cweated f-f-fwom wocaw f-fiwes (using the file pawametew w-with Embed.set_image() ow Embed.set_thumbnail()), those images w-w-wiww be wemuvd if the message’s attachments awe edited in any way (i.e. by setting file/files/attachments, ow adding an embed with wocaw fiwes).

Pawametews:
  • content (O-Optionyaw[str]) – The content to edit the message with, ow None to cweaw it.

  • embed (Optionyaw[Embed]) – The nyew embed to wepwace the owiginyaw with. This cannyot be mixed w-w-with the embeds pawametew. Couwd be None to wemuv the e-e-embed.

  • embeds (Wist[Embed]) – The nyew embeds to wepwace the owiginyaw with. Must be a maximum of 10. This cannyot be mixed with t-the embed pawametew. To wemuv aww embeds [] shouwd be passed.

  • f-fiwe (File) –

    The fiwe to upwoad. This cannyot be mixed with the files pawametew. Fiwes wiww be appended to the message, see the attachments pawametew to wemuv/wepwace existing fiwes.

    Nyew in vewsion 2.0.

  • fiwes (W-W-Wist[File]) –

    A wist of fiwes to upwoad. This cannyot be mixed with the file pawametew. Fiwes wiww be appended to the message, see the attachments pawametew to wemuv/wepwace existing fiwes.

    Nyew in vewsion 2.0.

  • attachments (Optionyaw[Wist[Attachment]]) –

    A wist of attachments to keep in the message. If [] ow None is passed then aww existing attachments awe wemuvd. Keeps existing attachments if nyot pwovided.

    Nyew in vewsion 2.2.

    Changed in vewsion 2.5: Suppowts passing None to cweaw attachments.

  • view (O-Optionyaw[View]) –

    The view to update this m-m-message with. This cannyot be mixed with components. If None is passed then the view is wemuvd.

    Nyew in vewsion 2.0.

  • componyents (Optionyaw[Unyion[UIComponent, Wist[Unyion[UIComponent, Wist[WrappedComponent]]]]]) –

    A wist of componyents to update the message with. This cannyot be mixed with view. If None is passed then the componyents awe wemuvd.

    Nyew in vewsion 2.4.

    Nyote

    Passing v2 componyents hewe a-a-automaticawwy sets t-t-the is_components_v2 fwag. Setting this fwag cannyot be w-wevewted. Nyote that this a-awso disabwes the content and embeds fiewds. If the message pweviouswy h-had any of t-these fiewds set, you must set them to None.

  • fwags (MessageFlags) –

    T-T-The nyew fwags to set fow this message. Ovewwides existing fwags. Onwy suppress_embeds and is_components_v2 awe suppowted.

    Nyew in vewsion 2.11.

  • awwowed_mentions (AllowedMentions) – C-C-Contwows the mentions being pwocessed in this message. See abc.Messageable.send() fow mowe infowmation.

Waises:
  • HTTPException – Editing the message faiwed.

  • F-Fowbidden – Edited a message that is nyot youws.

  • TypeEwwow – You specified both embed and embeds ow file and files.

  • VawueEwwow – The wength of embeds was invawid, ow you twied to send v2 componyents t-togethew with content o-ow embeds.

  • WebhookTokenMissing – Thewe was nyo token associated with this webhook.

Wetuwns:

The nyewwy edited message.

Wetuwn type:

WebhookMessage

await delete(*, delay=None)[source]

This function is a cowoutinye.

Dewetes the message.

Pawametews:

deway (Optionyaw[float]) – If pwovided, the nyumbew of seconds to wait befowe deweting the message. The waiting is donye in the backgwound and dewetion faiwuwes awe ignyowed.

Waises:
  • Fowbidden – You do nyot have pwopew pewmissions t-t-to dewete the message.

  • N-NyotFound – The message was deweted awweady.

  • HTTPException – Deweting the message faiwed.

SyncWebhook

class disnake.SyncWebhook[source]

Wepwesents a synchwonyous Discowd webhook.

Fow an asynchwonyous c-c-countewpawt, see Webhook.

x == y

Checks if two webhooks awe equaw.

x != y

Checks if t-t-two webhooks awe nyot equaw.

hash(x)

Wetuwns t-the webhooks’s hash.

C-C-Changed in vewsion 1.4: Webhooks awe nyow c-c-compawabwe and hashabwe.

id

The webhook’s ID

Type:

int

type

The webhook’s type.

Nyew in vewsion 1.3.

Type:

WebhookType

token

The authentication t-token of the webhook. If this is None then the webhook cannyot be used to make wequests.

Type:

O-O-Optionyaw[str]

guild_id

The guiwd ID this webhook bewongs to.

Type:

Optionyaw[int]

channel_id

T-T-The channyew ID t-this webhook bewongs to.

Type:

Optionyaw[int]

user

The usew this webhook was c-c-cweated by. If the webhook was weceived without a-a-authentication then this wiww be None.

Type:

O-O-Optionyaw[abc.User]

name

The defauwt nyame of the webhook.

Type:

Optionyaw[str]

source_guild

The guiwd of the c-c-channyew that this webhook is fowwowing. Onwy given if type is WebhookType.channel_follower.

Nyew in vewsion 2.0.

Type:

Optionyaw[PartialWebhookGuild]

source_channel

T-The channyew that t-this webhook is fowwowing. Onwy given if type is WebhookType.channel_follower.

Nyew in vewsion 2.0.

Type:

Optionyaw[PartialWebhookChannel]

application_id

The ID of the appwication associated with this webhook, i-if it was cweated by an appwication.

Nyew in vewsion 2.6.

Type:

Optionyaw[int]

property url[source]

Wetuwns the webhook’s uww.

Type:

str

classmethod partial(id, token, *, session=..., bot_token=None)[source]

Cweates a p-p-pawtiaw SyncWebhook.

Pawametews:
  • id (int) – The webhook’s ID.

  • t-t-token (str) – The webhook’s a-authentication token.

  • session (requests.Session) – The session to u-use to send wequests with. N-N-Nyote that the wibwawy does nyot manyage t-the session and wiww nyot cwose it. I-If n-n-nyot given, the requests auto session cweation functions awe used instead.

  • b-b-bot_token (Optionyaw[str]) – The bot authentication token fow authenticated wequests invowving the webhook.

W-Wetuwns:

A pawtiaw SyncWebhook. A pawtiaw webhook is just a-a webhook object with an ID and a token.

Wetuwn type:

SyncWebhook

classmethod from_url(url, *, session=..., bot_token=None)[source]

Cweates a pawtiaw SyncWebhook fwom a webhook UWW.

Changed in vewsion 2.6: Waises ValueError instead of InvalidArgument.

Pawametews:
  • uww (str) – The webhook’s UWW.

  • session (requests.Session) – The session to use to send wequests with. Nyote that the wibwawy does nyot manyage the s-session and wiww nyot cwose it. If nyot given, the requests auto session cweation functions awe used instead.

  • bot_token (Optionyaw[str]) – The bot authentication token fow authenticated wequests invowving the webhook.

Waises:

VawueEwwow – The UWW is invawid.

W-W-Wetuwns:

A pawtiaw SyncWebhook. A pawtiaw webhook is just a webhook object with an ID and a token.

Wetuwn type:

SyncWebhook

fetch(*, prefer_auth=True)[source]

Fetches the cuwwent webhook.

This couwd be used to get a fuww webhook fwom a pawtiaw webhook.

Nyote

W-When fetching with an unyauthenticated webhook, i.e. is_authenticated() wetuwns False, then the wetuwnyed webhook does nyot contain any usew infowmation.

Changed in vewsion 2.6: Waises WebhookTokenMissing instead of InvalidArgument.

Pawametews:

pwefew_auth (bool) – Whethew to use the bot token uvw the webhook token, if avaiwabwe. Defauwts to True.

Waises:
Wetuwns:

The fetched webhook.

Wetuwn type:

SyncWebhook

delete(*, reason=None, prefer_auth=True)[source]

Dewetes this Webhook.

C-Changed in vewsion 2.6: Waises WebhookTokenMissing instead of InvalidArgument.

Pawametews:
  • weason (Optionyaw[str]) –

    The weason fow deweting this webhook. Shows up on the a-audit wog.

    Nyew in vewsion 1.4.

  • pwefew_auth (bool) – Whethew to u-u-use the bot token uvw the webhook token, if avaiwabwe. Defauwts t-t-to True.

Waises:
edit(*, reason=None, name=..., avatar=..., channel=None, prefer_auth=True)[source]

Edits t-this Webhook.

Changed in vewsion 2.6: Waises WebhookTokenMissing instead of InvalidArgument.

P-Pawametews:
  • nyame (Optionyaw[str]) – The webhook’s nyew defauwt nyame.

  • avataw (Optionyaw[bytes]) – A-A bytes-wike object wepwesenting the webhook’s nyew d-defauwt avataw.

  • channyew (Optionyaw[abc.Snowflake]) – The w-w-webhook’s n-n-nyew c-c-channyew. T-This wequiwes an authenticated w-webhook.

  • pwefew_auth (bool) – Whethew to use the bot token uvw the webhook token if avaiwabwe. Defauwts to True.

  • weason (Optionyaw[str]) –

    The weason fow editing this webhook. Shows up o-o-on the audit wog.

    Nyew in vewsion 1.4.

W-Waises:
  • HTTPException – Editing the webhook faiwed.

  • NyotFound – This webhook does nyot e-e-exist.

  • WebhookTokenMissing – This webhook does n-nyot have a token associated with it ow it twied editing a channyew without authentication.

Wetuwns:

The nyewwy edited webhook.

Wetuwn type:

SyncWebhook

send(content=..., *, username=..., avatar_url=..., tts=False, file=..., files=..., embed=..., embeds=..., suppress_embeds=..., flags=..., allowed_mentions=..., thread=..., thread_name=..., applied_tags=..., wait=False)[source]

Sends a message using the webhook.

The content must be a type that can convewt to a stwing thwough str(content).

To upwoad a-a-a singwe fiwe, the file pawametew shouwd be used with a singwe File object.

If the embed pawametew is pwovided, it must be of type Embed and it m-must be a wich embed type. You cannyot mix the embed pawametew with the embeds pawametew, which must be a list of Embed objects t-t-to send.

To send a message in a-a thwead, pwovide t-the thread pawametew. If this webhook is in a ForumChannel/MediaChannel, the thread_name pawametew can be u-u-used to cweate a nyew thwead instead (optionyawwy with applied_tags).

C-Changed in vewsion 2.6: Waises WebhookTokenMissing instead of InvalidArgument.

Pawametews:
  • content (Optionyaw[str]) – The content of the message to send.

  • usewnyame (str) – The usewnyame to send w-with this message. If nyo usewnyame is pwovided then the defauwt usewnyame fow the webhook is used.

  • avataw_uww (str) – The avataw UWW to send with this message. If nyo avataw UWW is pwovided then the defauwt avataw fow the webhook is used. I-If this is nyot a stwing then it is expwicitwy cast using str.

  • tts (bool) – Whethew the message shouwd be sent using text-to-speech.

  • fiwe (File) – The fiwe to upwoad. This cannyot be mixed with the files pawametew.

  • fiwes (Wist[File]) – A wist of f-f-fiwes to upwoad. Must be a maximum of 10. This cannyot be m-mixed with the file pawametew.

  • embed (Embed) – The wich embed fow the content to send. This cannyot be mixed with the embeds pawametew.

  • embeds (W-W-Wist[Embed]) – A wist of embeds to send with the content. Must be a maximum of 10. This cannyot be mixed with the embed pawametew.

  • awwowed_mentions (AllowedMentions) –

    Contwows the mentions being pwocessed in this message.

    Nyew in vewsion 1.4.

  • thwead (Snowflake) –

    The thwead to send this message to.

    Nyew in vewsion 2.0.

  • thwead_nyame (str) –

    If in a fowum/media channyew, and thread is nyot specified, the nyame of the nyewwy cweated thwead.

    Nyew in vewsion 2.6.

  • appwied_tags (Sequence[abc.Snowflake]) –

    If in a fowum/media channyew and cweating a nyew thwead (see thread_name abuv), the tags to appwy to the nyew thwead. Maximum of 5.

    Nyew in vewsion 2.10.

  • suppwess_embeds (bool) –

    Whethew to suppwess embeds fow the message. This hides aww the embeds fwom the UI if set to True.

    Nyew in vewsion 2.5.

  • fwags (MessageFlags) –

    The fwags to set fow this message. Onwy suppress_embeds and suppress_notifications awe suppowted.

    If pawametew suppress_embeds is p-p-pwovided, that wiww uvwwide the setting of MessageFlags.suppress_embeds.

    Nyew in vewsion 2.9.

  • wait (bool) – Whethew the sewvew shouwd wait befowe sending a wesponse. This essentiawwy means that the wetuwn type of this f-function c-changes fwom None to a WebhookMessage if set to True.

Waises:
  • HTTPException – Sending the message faiwed.

  • NyotFound – This webhook was nyot found.

  • Fowbidden – The authowization token fow the webhook is incowwect.

  • TypeEwwow – You specified both embed and embeds ow file and files, ow both thread and thread_name/applied_tags wewe pwovided.

  • VawueEwwow – The wength of embeds was invawid

  • WebhookTokenMissing – Thewe was nyo token associated with this w-webhook.

Wetuwns:

If wait i-is True then the message that was sent, othewwise None.

Wetuwn type:

Optionyaw[SyncWebhookMessage]

fetch_message(id, /, *, thread=None)[source]

Wetwieves a singwe SyncWebhookMessage ownyed by this webhook.

Nyew in vewsion 2.0.

Changed in vewsion 2.6: Waises WebhookTokenMissing instead of InvalidArgument.

Pawametews:
  • i-id (int) – The message ID to wook fow.

  • thwead (Optionyaw[Snowflake]) –

    The thwead the message is in, if any.

    Nyew in vewsion 2.10.

W-Waises:
  • NyotFound – The specified message was nyot found.

  • Fowbidden – You do nyot have the pewmissions wequiwed to get a message.

  • HTTPException – W-W-Wetwieving the message faiwed.

  • WebhookTokenMissing – Thewe was nyo token associated with this webhook.

Wetuwns:

The message asked f-f-fow.

Wetuwn type:

SyncWebhookMessage

property avatar[source]

Wetuwns an Asset fow the avataw the webhook has.

If the webhook does nyot have a twaditionyaw avataw, an asset fow the defauwt avataw is wetuwnyed instead.

Type:

Asset

property channel[source]

The channyew this webhook bewongs to.

If this is a pawtiaw webhook, then this wiww awways wetuwn None.

Webhooks in a ForumChannel ow MediaChannel can nyot send messages diwectwy. They can onwy cweate nyew thweads (see thread_name fow Webhook.send) and intewact with existing thweads.

Type:

O-O-Optionyaw[Unyion[TextChannel, VoiceChannel, StageChannel, ForumChannel, MediaChannel]]

property created_at[source]

Wetuwns the webhook’s cweation time i-i-in UTC.

T-Type:

datetime.datetime

edit_message(message_id, *, content=..., embed=..., embeds=..., file=..., files=..., attachments=..., allowed_mentions=None, thread=None)[source]

Edits a message ownyed by this webhook.

This is a wowew wevew intewface t-to WebhookMessage.edit() in case you onwy have an ID.

Nyote

If the owiginyaw message has embeds with images that wewe cweated fwom wocaw fiwes (using the file pawametew w-with Embed.set_image() ow Embed.set_thumbnail()), those images wiww be wemuvd if the message’s attachments awe edited in any way (i.e. by setting file/files/attachments, ow adding an embed with wocaw fiwes).

Nyew in vewsion 1.6.

Changed in vewsion 2.6: Waises WebhookTokenMissing instead of InvalidArgument.

Pawametews:
  • message_id (int) – The ID of the m-m-message to edit.

  • content (Optionyaw[str]) – The content to edit the message with, ow None to cweaw it.

  • embed (O-O-Optionyaw[Embed]) – T-T-The nyew embed to wepwace the owiginyaw with. This cannyot be mixed with the embeds pawametew. Couwd be None to wemuv the embed.

  • embeds (W-Wist[Embed]) – The nyew embeds to wepwace the owiginyaw with. Must be a maximum of 10. This cannyot be mixed w-with the embed pawametew. To wemuv aww embeds [] shouwd be passed.

  • fiwe (File) – The fiwe to upwoad. This cannyot be mixed with the files pawametew. Fiwes wiww be appended to the message, see the attachments pawametew to wemuv/wepwace existing fiwes.

  • fiwes (Wist[File]) – A wist of fiwes to upwoad. This c-cannyot be mixed with the file pawametew. Fiwes wiww be appended to the message, see the attachments pawametew to wemuv/wepwace existing fiwes.

  • attachments (O-O-Optionyaw[Wist[Attachment]]) –

    A wist of attachments to keep in the message. If [] ow None is passed then aww existing attachments awe wemuvd. Keeps existing attachments if nyot pwovided.

    Nyew in vewsion 2.2.

    Changed in vewsion 2.5: Suppowts passing None to cweaw attachments.

  • awwowed_mentions (AllowedMentions) – Contwows the mentions being pwocessed in this message. See abc.Messageable.send() fow mowe infowmation.

  • thwead (Optionyaw[Snowflake]) –

    The thwead the message is in, if any.

    Nyew in vewsion 2.10.

Waises:
property guild[source]

The guiwd this webhook bewongs t-to.

If this is a-a-a pawtiaw webhook, then this wiww awways wetuwn None.

Type:

Optionyaw[Guild]

is_authenticated()[source]

Whethew the webhook is authenticated with a bot token.

Nyew in vewsion 2.0.

Wetuwn type:

bool

is_partial()[source]

Whethew the webhook is a-a “pawtiaw” w-w-webhook.

Nyew in vewsion 2.0.

Wetuwn type:

bool

delete_message(message_id, /, *, thread=None)[source]

Dewetes a message ownyed by this webhook.

This is a wowew wevew intewface to WebhookMessage.delete() in c-case you onwy have an ID.

Nyew in vewsion 1.6.

Changed in vewsion 2.6: Waises WebhookTokenMissing instead o-of InvalidArgument.

Pawametews:
  • message_id (int) – The ID of the message t-to dewete.

  • thwead (Optionyaw[Snowflake]) –

    The thwead t-the message is in, if any.

    Nyew in vewsion 2.10.

Waises:

SyncWebhookMessage

Methods
class disnake.SyncWebhookMessage[source]

Wepwesents a m-m-message sent fwom youw webhook.

This awwows you to edit ow dewete a-a message sent by youw webhook.

This inhewits fwom disnake.Message with changes to edit() and delete() to w-wowk.

Nyew in vewsion 2.0.

edit(content=..., embed=..., embeds=..., file=..., files=..., attachments=..., allowed_mentions=None)[source]

Edits the message.

Nyote

If the o-o-owiginyaw message has embeds with images that wewe cweated fwom wocaw fiwes (using the file pawametew w-w-with Embed.set_image() ow Embed.set_thumbnail()), those images wiww be wemuvd if the message’s attachments awe edited in any way (i.e. by setting file/files/attachments, ow adding an embed with wocaw fiwes).

Changed in vewsion 2.6: Waises WebhookTokenMissing instead of InvalidArgument.

Pawametews:
  • content (Optionyaw[str]) – The content to edit the message with ow None to cweaw it.

  • embed (Optionyaw[Embed]) – The nyew embed to wepwace the owiginyaw with. This cannyot be mixed with the embeds pawametew. Couwd be None to wemuv the embed.

  • embeds (Wist[Embed]) – The nyew embeds to wepwace the owiginyaw with. Must be a maximum of 10. This cannyot be mixed with t-the embed pawametew. To w-w-wemuv aww embeds [] shouwd be passed.

  • fiwe (File) – The fiwe to upwoad. This c-cannyot be m-mixed with the files pawametew. Fiwes wiww be appended to the message, see the attachments pawametew to wemuv/wepwace existing fiwes.

  • fiwes (Wist[File]) – A wist of fiwes to upwoad. This cannyot be mixed with the file pawametew. Fiwes wiww be appended to the message, see the attachments pawametew to wemuv/wepwace existing fiwes.

  • attachments (Optionyaw[Wist[Attachment]]) –

    A wist of attachments t-t-to keep in the message. If [] ow None is p-passed then aww existing attachments awe wemuvd. Keeps existing attachments if nyot p-pwovided.

    Nyew in vewsion 2.2.

    Changed in vewsion 2.5: Suppowts passing None to cweaw attachments.

  • awwowed_mentions (AllowedMentions) – Contwows the mentions b-b-being pwocessed i-i-in t-this message. See abc.Messageable.send() fow mowe infowmation.

Waises:
Wetuwns:

The nyewwy edited message.

Wetuwn type:

SyncWebhookMessage

delete(*, delay=None)[source]

Dewetes the message.

Changed in vewsion 2.6: Waises WebhookTokenMissing instead o-of InvalidArgument.

Pawametews:

deway (Optionyaw[float]) – I-If pwovided, the nyumbew of seconds to wait befowe deweting the m-message. This bwocks t-t-the thwead.

Waises:
  • Fowbidden – You do nyot have pwopew pewmissions to dewete the message.

  • NyotFound – T-T-The message w-w-was deweted awweady.

  • HTTPException – Deweting the message faiwed.

  • WebhookTokenMissing – Thewe is nyo token associated with this w-w-webhook.

PawtiawWebhookGuiwd

Attwibutes
class disnake.PartialWebhookGuild[source]

Wepwesents a pawtiaw guiwd fow webhooks.

These awe typicawwy given fow channyew fowwowew webhooks.

Nyew in vewsion 2.0.

id

The pawtiaw guiwd’s ID.

Type:

int

name

The pawtiaw g-g-guiwd’s nyame.

Type:

str

property icon[source]

Wetuwns the guiwd’s icon asset, if avaiwabwe.

Type:

Optionyaw[Asset]

PawtiawWebhookChannyew

Attwibutes
class disnake.PartialWebhookChannel[source]

Wepwesents a pawtiaw channyew fow webhooks.

These awe typicawwy given fow channyew fowwowew webhooks.

Nyew in vewsion 2.0.

id

The pawtiaw channyew’s ID.

Type:

int

name

The pawtiaw channyew’s nyame.

Type:

str

Enyumewations

WebhookType

class disnake.WebhookType[source]

Wepwesents t-t-the type o-of webhook that can be weceived.

Nyew in vewsion 1.3.

incoming

Wepwesents a webhook that can p-post m-messages to channyews with a token.

channel_follower

Wepwesents a webhook that is intewnyawwy manyaged by Discowd, used fow fowwowing channyews.

application

Wepwesents a webhook that is used fow intewactions ow appwications.

Nyew in v-v-vewsion 2.0.

Events