Webhooks¶
This section documents all objects related to webhooks, a low-effort way of sending messages in channels without a user/bot account.
Discord Models¶
Webhook¶
- clsWebhook.from_url
- clsWebhook.partial
- asyncdelete
- asyncdelete_message
- asyncedit
- asyncedit_message
- asyncfetch
- asyncfetch_message
- defis_authenticated
- defis_partial
- asyncsend
- class disnake.Webhook[source]¶
Represents an asynchronous Discord webhook.
Webhooks are a form to send messages to channels in Discord without a bot user or authentication.
There are two main ways to use Webhooks. The first is through the ones received by the library such as
Guild.webhooks(),TextChannel.webhooks(),VoiceChannel.webhooks(),ForumChannel.webhooks(),MediaChannel.webhooks()andStageChannel.webhooks(). The ones received by the library will automatically be bound using the library’s internal HTTP session.The second form involves creating a webhook object manually using the
from_url()orpartial()classmethods.For example, creating a webhook from a URL 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')
For a synchronous counterpart, see
SyncWebhook.- x == y
Checks if two webhooks are equal.
- x != y
Checks if two webhooks are not equal.
- hash(x)
Returns the webhooks’s hash.
Changed in version 1.4: Webhooks are now comparable and hashable.
- type¶
The webhook’s type.
New in version 1.3.
- Type:
- token¶
The authentication token of the webhook. If this is
Nonethen the webhook cannot be used to make requests.
- user¶
The user this webhook was created by. If the webhook was received without authentication then this will be
None.
- source_guild¶
The guild of the channel that this webhook is following. Only given if
typeisWebhookType.channel_follower.New in version 2.0.
- Type:
- source_channel¶
The channel that this webhook is following. Only given if
typeisWebhookType.channel_follower.New in version 2.0.
- Type:
- application_id¶
The ID of the application associated with this webhook, if it was created by an application.
New in version 2.6.
- classmethod partial(id, token, *, session, bot_token=None)[source]¶
Creates a partial
Webhook.- Parameters:
id (
int) – The webhook’s ID.token (
str) – The webhook’s authentication token.session (
aiohttp.ClientSession) –The session to use to send requests with. Note that the library does not manage the session and will not close it.
New in version 2.0.
The bot authentication token for authenticated requests involving the webhook.
New in version 2.0.
- Returns:
A partial
Webhook. A partial webhook is just a webhook object with an ID and a token.- Return type:
- classmethod from_url(url, *, session, bot_token=None)[source]¶
Creates a partial
Webhookfrom a webhook URL.Changed in version 2.6: Raises
ValueErrorinstead ofInvalidArgument.- Parameters:
url (
str) – The webhook’s URL.session (
aiohttp.ClientSession) –The session to use to send requests with. Note that the library does not manage the session and will not close it.
New in version 2.0.
The bot authentication token for authenticated requests involving the webhook.
New in version 2.0.
- Raises:
ValueError – The URL is invalid.
- Returns:
A partial
Webhook. A partial webhook is just a webhook object with an ID and a token.- Return type:
- await fetch(*, prefer_auth=True)[source]¶
This function is a coroutine.
Fetches the current webhook.
This could be used to get a full webhook from a partial webhook.
New in version 2.0.
Note
When fetching with an unauthenticated webhook, i.e.
is_authenticated()returnsFalse, then the returned webhook does not contain any user information.Changed in version 2.6: Raises
WebhookTokenMissinginstead ofInvalidArgument.- Parameters:
prefer_auth (
bool) – Whether to use the bot token over the webhook token, if available. Defaults toTrue.- Raises:
HTTPException – Could not fetch the webhook
NotFound – Could not find the webhook by this ID
WebhookTokenMissing – This webhook does not have a token associated with it.
- Returns:
The fetched webhook.
- Return type:
- await delete(*, reason=None, prefer_auth=True)[source]¶
This function is a coroutine.
Deletes this Webhook.
Changed in version 2.6: Raises
WebhookTokenMissinginstead ofInvalidArgument.- Parameters:
- Raises:
HTTPException – Deleting the webhook failed.
NotFound – This webhook does not exist.
Forbidden – You do not have permissions to delete this webhook.
WebhookTokenMissing – This webhook does not have a token associated with it.
- await edit(*, reason=None, name=..., avatar=..., channel=None, prefer_auth=True)[source]¶
This function is a coroutine.
Edits this Webhook.
Changed in version 2.6: Raises
WebhookTokenMissinginstead ofInvalidArgument.- Parameters:
avatar (
bytes|Asset|Emoji|PartialEmoji|StickerItem|Sticker|None) –The webhook’s new default avatar.
Changed in version 2.5: Now accepts various resource types in addition to
bytes.channel (
abc.Snowflake|None) –The webhook’s new channel. This requires an authenticated webhook.
New in version 2.0.
prefer_auth (
bool) –Whether to use the bot token over the webhook token if available. Defaults to
True.New in version 2.0.
The reason for editing this webhook. Shows up on the audit log.
New in version 1.4.
- Raises:
HTTPException – Editing the webhook failed.
NotFound – This webhook does not exist or the
avatarasset couldn’t be found.TypeError – The
avatarasset is a lottie sticker (seeSticker.read()).WebhookTokenMissing – This webhook does not have a token associated with it or it tried editing a channel without authentication.
- Returns:
The newly edited webhook.
- Return type:
- property avatar[source]¶
Returns an
Assetfor the avatar the webhook has.If the webhook does not have a traditional avatar, an asset for the default avatar is returned instead.
- Type:
- property channel[source]¶
The channel this webhook belongs to.
If this is a partial webhook, then this will always return
None.Webhooks in a
ForumChannelorMediaChannelcan not send messages directly. They can only create new threads (seethread_nameforWebhook.send) and interact with existing threads.- Type:
TextChannel|VoiceChannel|StageChannel|ForumChannel|MediaChannel|None
- property guild[source]¶
The guild this webhook belongs to.
If this is a partial webhook, then this will always return
None.
- is_authenticated()[source]¶
Whether the webhook is authenticated with a bot token.
New in version 2.0.
- Return type:
- 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 coroutine.
Sends a message using the webhook.
The content must be a type that can convert to a string through
str(content).To upload a single file, the
fileparameter should be used with a singleFileobject.If the
embedparameter is provided, it must be of typeEmbedand it must be a rich embed type. You cannot mix theembedparameter with theembedsparameter, which must be alistofEmbedobjects to send.To send a message in a thread, provide the
threadparameter. If this webhook is in aForumChannel/MediaChannel, thethread_nameparameter can be used to create a new thread instead (optionally withapplied_tags).Changed in version 2.6: Raises
WebhookTokenMissinginstead ofInvalidArgument.- Parameters:
username (
str) – The username to send with this message. If no username is provided then the default username for the webhook is used.avatar_url (
str) – The avatar URL to send with this message. If no avatar URL is provided then the default avatar for the webhook is used. If this is not a string then it is explicitly cast usingstr.tts (
bool) – Whether the message should be sent using text-to-speech.ephemeral (
bool) –Whether the message should only be visible to the user. This is only available to
WebhookType.applicationwebhooks. If a view is sent with an ephemeral message and it has no timeout set then the timeout is set to 15 minutes.New in version 2.0.
file (
File) – The file to upload. This cannot be mixed with thefilesparameter.files (
list[File]) – A list of files to upload. Must be a maximum of 10. This cannot be mixed with thefileparameter.embed (
Embed) – The rich embed for the content to send. This cannot be mixed with theembedsparameter.embeds (
list[Embed]) – A list of embeds to send with the content. Must be a maximum of 10. This cannot be mixed with theembedparameter.allowed_mentions (
AllowedMentions) –Controls the mentions being processed in this message. If this is passed, then the object is merged with
Client.allowed_mentions, if applicable. The merging behaviour only overrides attributes that have been explicitly passed to the object, otherwise it uses the attributes set inClient.allowed_mentions. If no object is passed at all then the defaults given byClient.allowed_mentionsare used instead.New in version 1.4.
view (
disnake.ui.View) –The view to send with the message. You can only send a view if this webhook is not partial and has state attached. A webhook has state attached if the webhook is managed by the library. This cannot be mixed with
components.New in version 2.0.
components (
UIComponent|list[UIComponent|list[WrappedComponent]]) –A list of components to include in the message. This cannot be mixed with
view.New in version 2.4.
Note
Passing v2 components here automatically sets the
is_components_v2flag. Setting this flag cannot be reverted. Note that this also disables thecontent,embeds, andpollfields.Note
Non-application-owned webhooks can only send non-interactive components, e.g. link buttons or v2 layout components.
thread (
Snowflake) –The thread to send this message to.
New in version 2.0.
thread_name (
str) –If in a forum/media channel, and
threadis not specified, the name of the newly created thread.Note
If this is set, the returned message’s
channel(assumingwait=True), representing the created thread, may be aPartialMessageable.New in version 2.6.
applied_tags (
Sequence[abc.Snowflake]) –If in a forum/media channel and creating a new thread (see
thread_nameabove), the tags to apply to the new thread. Maximum of 5.New in version 2.10.
wait (
bool) – Whether the server should wait before sending a response. This essentially means that the return type of this function changes fromNoneto aWebhookMessageif set toTrue. If the type of webhook isWebhookType.applicationthen this is always set toTrue.delete_after (
float) –If provided, the number of seconds to wait in the background before deleting the message we just sent. If the deletion fails, then it is silently ignored.
New in version 2.1.
Changed in version 2.7: Added support for ephemeral interaction responses.
suppress_embeds (
bool) –Whether to suppress embeds for the message. This hides all the embeds from the UI if set to
True.New in version 2.5.
flags (
MessageFlags) –The flags to set for this message. Only
suppress_embeds,ephemeral,suppress_notifications, andis_components_v2are supported.If parameters
suppress_embedsorephemeralare provided, they will override the corresponding setting of thisflagsparameter.New in version 2.9.
poll (
Poll) –The poll to send with the message.
New in version 2.10.
- Raises:
HTTPException – Sending the message failed.
NotFound – This webhook was not found.
Forbidden – The authorization token for the webhook is incorrect.
TypeError – Raised by any of the following: You specified both
embedandembedsorfileandfiles.ephemeralwas passed with the improper webhook type. There was no state attached with this webhook when giving it a view. Boththreadandthread_name/applied_tagswere provided.WebhookTokenMissing – There was no token associated with this webhook.
ValueError – The length of
embedswas invalid, or you tried to send v2 components together withcontent,embeds, orpoll.
- Returns:
If
waitisTruethen the message that was sent, otherwiseNone.- Return type:
- await fetch_message(id, *, thread=None)[source]¶
This function is a coroutine.
Retrieves a single
WebhookMessageowned by this webhook.New in version 2.0.
Changed in version 2.6: Raises
WebhookTokenMissinginstead ofInvalidArgument.- Parameters:
- Raises:
NotFound – The specified message was not found.
Forbidden – You do not have the permissions required to get a message.
HTTPException – Retrieving the message failed.
WebhookTokenMissing – There was no token associated with this webhook.
- Returns:
The message asked for.
- Return type:
- await edit_message(message_id, *, content=..., embed=..., embeds=..., file=..., files=..., attachments=..., view=..., components=..., flags=..., allowed_mentions=None, thread=None)[source]¶
This function is a coroutine.
Edits a message owned by this webhook.
This is a lower level interface to
WebhookMessage.edit()in case you only have an ID.Note
If the original message has embeds with images that were created from local files (using the
fileparameter withEmbed.set_image()orEmbed.set_thumbnail()), those images will be removed if the message’s attachments are edited in any way (i.e. by settingfile/files/attachments, or adding an embed with local files).New in version 1.6.
Changed in version 2.0: The edit is no longer in-place, instead the newly edited message is returned.
Changed in version 2.6: Raises
WebhookTokenMissinginstead ofInvalidArgument.- Parameters:
message_id (
int) – The ID of the message to edit.content (
str|None) – The content to edit the message with, orNoneto clear it.embed (
Embed|None) – The new embed to replace the original with. This cannot be mixed with theembedsparameter. Could beNoneto remove the embed.embeds (
list[Embed]) – The new embeds to replace the original with. Must be a maximum of 10. This cannot be mixed with theembedparameter. To remove all embeds[]should be passed.file (
File) –The file to upload. This cannot be mixed with the
filesparameter. Files will be appended to the message, see theattachmentsparameter to remove/replace existing files.New in version 2.0.
A list of files to upload. This cannot be mixed with the
fileparameter. Files will be appended to the message, see theattachmentsparameter to remove/replace existing files.New in version 2.0.
attachments (
list[Attachment] |None) –A list of attachments to keep in the message. If
[]orNoneis passed then all existing attachments are removed. Keeps existing attachments if not provided.New in version 2.2.
Changed in version 2.5: Supports passing
Noneto clear attachments.The updated view to update this message with. If
Noneis passed then the view is removed. The webhook must have state attached, similar tosend(). This cannot be mixed withcomponents.New in version 2.0.
components (
UIComponent|list[UIComponent|list[WrappedComponent]] |None) –A list of components to update this message with. This cannot be mixed with
view. IfNoneis passed then the components are removed.New in version 2.4.
Note
Passing v2 components here automatically sets the
is_components_v2flag. Setting this flag cannot be reverted. Note that this also disables thecontentandembedsfields. If the message previously had any of these fields set, you must set them toNone.flags (
MessageFlags) –The new flags to set for this message. Overrides existing flags. Only
suppress_embedsandis_components_v2are supported.New in version 2.11.
allowed_mentions (
AllowedMentions) – Controls the mentions being processed in this message. Seeabc.Messageable.send()for more information.The thread the message is in, if any.
New in version 2.10.
- Raises:
HTTPException – Editing the message failed.
Forbidden – Edited a message that is not yours.
TypeError – You specified both
embedandembedsorfileandfilesor there is no associated state when sending a view.WebhookTokenMissing – There was no token associated with this webhook.
ValueError – The length of
embedswas invalid, or you tried to send v2 components together withcontentorembeds.
- Returns:
The newly edited webhook message.
- Return type:
- await delete_message(message_id, /, *, thread=None)[source]¶
This function is a coroutine.
Deletes a message owned by this webhook.
This is a lower level interface to
WebhookMessage.delete()in case you only have an ID.New in version 1.6.
Changed in version 2.6: Raises
WebhookTokenMissinginstead ofInvalidArgument.- Parameters:
- Raises:
HTTPException – Deleting the message failed.
Forbidden – Deleted a message that is not yours.
WebhookTokenMissing – There was no token associated with this webhook
WebhookMessage¶
- class disnake.WebhookMessage[source]¶
Represents a message sent from your webhook.
This allows you to edit or delete a message sent by your webhook.
This inherits from
disnake.Messagewith changes toedit()anddelete()to work.New in version 1.6.
- await edit(content=..., embed=..., embeds=..., file=..., files=..., attachments=..., view=..., components=..., flags=..., allowed_mentions=None)[source]¶
This function is a coroutine.
Edits the message.
New in version 1.6.
Changed in version 2.0: The edit is no longer in-place, instead the newly edited message is returned.
Note
If the original message has embeds with images that were created from local files (using the
fileparameter withEmbed.set_image()orEmbed.set_thumbnail()), those images will be removed if the message’s attachments are edited in any way (i.e. by settingfile/files/attachments, or adding an embed with local files).- Parameters:
content (
str|None) – The content to edit the message with, orNoneto clear it.embed (
Embed|None) – The new embed to replace the original with. This cannot be mixed with theembedsparameter. Could beNoneto remove the embed.embeds (
list[Embed]) – The new embeds to replace the original with. Must be a maximum of 10. This cannot be mixed with theembedparameter. To remove all embeds[]should be passed.file (
File) –The file to upload. This cannot be mixed with the
filesparameter. Files will be appended to the message, see theattachmentsparameter to remove/replace existing files.New in version 2.0.
A list of files to upload. This cannot be mixed with the
fileparameter. Files will be appended to the message, see theattachmentsparameter to remove/replace existing files.New in version 2.0.
attachments (
list[Attachment] |None) –A list of attachments to keep in the message. If
[]orNoneis passed then all existing attachments are removed. Keeps existing attachments if not provided.New in version 2.2.
Changed in version 2.5: Supports passing
Noneto clear attachments.The view to update this message with. This cannot be mixed with
components. IfNoneis passed then the view is removed.New in version 2.0.
components (
UIComponent|list[UIComponent|list[WrappedComponent]] |None) –A list of components to update the message with. This cannot be mixed with
view. IfNoneis passed then the components are removed.New in version 2.4.
Note
Passing v2 components here automatically sets the
is_components_v2flag. Setting this flag cannot be reverted. Note that this also disables thecontentandembedsfields. If the message previously had any of these fields set, you must set them toNone.flags (
MessageFlags) –The new flags to set for this message. Overrides existing flags. Only
suppress_embedsandis_components_v2are supported.New in version 2.11.
allowed_mentions (
AllowedMentions) – Controls the mentions being processed in this message. Seeabc.Messageable.send()for more information.
- Raises:
HTTPException – Editing the message failed.
Forbidden – Edited a message that is not yours.
TypeError – You specified both
embedandembedsorfileandfiles.ValueError – The length of
embedswas invalid, or you tried to send v2 components together withcontentorembeds.WebhookTokenMissing – There was no token associated with this webhook.
- Returns:
The newly edited message.
- Return type:
- await delete(*, delay=None)[source]¶
This function is a coroutine.
Deletes the message.
- Parameters:
delay (
float|None) – If provided, the number of seconds to wait before deleting the message. The waiting is done in the background and deletion failures are ignored.- Raises:
Forbidden – You do not have proper permissions to delete the message.
NotFound – The message was deleted already.
HTTPException – Deleting the message failed.
SyncWebhook¶
- clsSyncWebhook.from_url
- clsSyncWebhook.partial
- defdelete
- defdelete_message
- defedit
- defedit_message
- deffetch
- deffetch_message
- defis_authenticated
- defis_partial
- defsend
- class disnake.SyncWebhook[source]¶
Represents a synchronous Discord webhook.
For an asynchronous counterpart, see
Webhook.- x == y
Checks if two webhooks are equal.
- x != y
Checks if two webhooks are not equal.
- hash(x)
Returns the webhooks’s hash.
Changed in version 1.4: Webhooks are now comparable and hashable.
- type¶
The webhook’s type.
New in version 1.3.
- Type:
- token¶
The authentication token of the webhook. If this is
Nonethen the webhook cannot be used to make requests.
- user¶
The user this webhook was created by. If the webhook was received without authentication then this will be
None.
- source_guild¶
The guild of the channel that this webhook is following. Only given if
typeisWebhookType.channel_follower.New in version 2.0.
- Type:
- source_channel¶
The channel that this webhook is following. Only given if
typeisWebhookType.channel_follower.New in version 2.0.
- Type:
- application_id¶
The ID of the application associated with this webhook, if it was created by an application.
New in version 2.6.
- classmethod partial(id, token, *, session=..., bot_token=None)[source]¶
Creates a partial
SyncWebhook.- Parameters:
id (
int) – The webhook’s ID.token (
str) – The webhook’s authentication token.session (
requests.Session) – The session to use to send requests with. Note that the library does not manage the session and will not close it. If not given, therequestsauto session creation functions are used instead.bot_token (
str|None) – The bot authentication token for authenticated requests involving the webhook.
- Returns:
A partial
SyncWebhook. A partial webhook is just a webhook object with an ID and a token.- Return type:
- classmethod from_url(url, *, session=..., bot_token=None)[source]¶
Creates a partial
SyncWebhookfrom a webhook URL.Changed in version 2.6: Raises
ValueErrorinstead ofInvalidArgument.- Parameters:
url (
str) – The webhook’s URL.session (
requests.Session) – The session to use to send requests with. Note that the library does not manage the session and will not close it. If not given, therequestsauto session creation functions are used instead.bot_token (
str|None) – The bot authentication token for authenticated requests involving the webhook.
- Raises:
ValueError – The URL is invalid.
- Returns:
A partial
SyncWebhook. A partial webhook is just a webhook object with an ID and a token.- Return type:
- fetch(*, prefer_auth=True)[source]¶
Fetches the current webhook.
This could be used to get a full webhook from a partial webhook.
Note
When fetching with an unauthenticated webhook, i.e.
is_authenticated()returnsFalse, then the returned webhook does not contain any user information.Changed in version 2.6: Raises
WebhookTokenMissinginstead ofInvalidArgument.- Parameters:
prefer_auth (
bool) – Whether to use the bot token over the webhook token, if available. Defaults toTrue.- Raises:
HTTPException – Could not fetch the webhook
NotFound – Could not find the webhook by this ID
WebhookTokenMissing – This webhook does not have a token associated with it.
- Returns:
The fetched webhook.
- Return type:
- delete(*, reason=None, prefer_auth=True)[source]¶
Deletes this Webhook.
Changed in version 2.6: Raises
WebhookTokenMissinginstead ofInvalidArgument.- Parameters:
- Raises:
HTTPException – Deleting the webhook failed.
NotFound – This webhook does not exist.
Forbidden – You do not have permissions to delete this webhook.
WebhookTokenMissing – This webhook does not have a token associated with it.
- edit(*, reason=None, name=..., avatar=..., channel=None, prefer_auth=True)[source]¶
Edits this Webhook.
Changed in version 2.6: Raises
WebhookTokenMissinginstead ofInvalidArgument.- Parameters:
avatar (
bytes|None) – A bytes-like object representing the webhook’s new default avatar.channel (
abc.Snowflake|None) – The webhook’s new channel. This requires an authenticated webhook.prefer_auth (
bool) – Whether to use the bot token over the webhook token if available. Defaults toTrue.The reason for editing this webhook. Shows up on the audit log.
New in version 1.4.
- Raises:
HTTPException – Editing the webhook failed.
NotFound – This webhook does not exist.
WebhookTokenMissing – This webhook does not have a token associated with it or it tried editing a channel without authentication.
- Returns:
The newly edited webhook.
- Return type:
- property avatar[source]¶
Returns an
Assetfor the avatar the webhook has.If the webhook does not have a traditional avatar, an asset for the default avatar is returned instead.
- Type:
- property channel[source]¶
The channel this webhook belongs to.
If this is a partial webhook, then this will always return
None.Webhooks in a
ForumChannelorMediaChannelcan not send messages directly. They can only create new threads (seethread_nameforWebhook.send) and interact with existing threads.- Type:
TextChannel|VoiceChannel|StageChannel|ForumChannel|MediaChannel|None
- property guild[source]¶
The guild this webhook belongs to.
If this is a partial webhook, then this will always return
None.
- is_authenticated()[source]¶
Whether the webhook is authenticated with a bot token.
New in version 2.0.
- Return type:
- 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 convert to a string through
str(content).To upload a single file, the
fileparameter should be used with a singleFileobject.If the
embedparameter is provided, it must be of typeEmbedand it must be a rich embed type. You cannot mix theembedparameter with theembedsparameter, which must be alistofEmbedobjects to send.To send a message in a thread, provide the
threadparameter. If this webhook is in aForumChannel/MediaChannel, thethread_nameparameter can be used to create a new thread instead (optionally withapplied_tags).Changed in version 2.6: Raises
WebhookTokenMissinginstead ofInvalidArgument.- Parameters:
username (
str) – The username to send with this message. If no username is provided then the default username for the webhook is used.avatar_url (
str) – The avatar URL to send with this message. If no avatar URL is provided then the default avatar for the webhook is used. If this is not a string then it is explicitly cast usingstr.tts (
bool) – Whether the message should be sent using text-to-speech.file (
File) – The file to upload. This cannot be mixed with thefilesparameter.files (
list[File]) – A list of files to upload. Must be a maximum of 10. This cannot be mixed with thefileparameter.embed (
Embed) – The rich embed for the content to send. This cannot be mixed with theembedsparameter.embeds (
list[Embed]) – A list of embeds to send with the content. Must be a maximum of 10. This cannot be mixed with theembedparameter.allowed_mentions (
AllowedMentions) –Controls the mentions being processed in this message.
New in version 1.4.
thread (
Snowflake) –The thread to send this message to.
New in version 2.0.
thread_name (
str) –If in a forum/media channel, and
threadis not specified, the name of the newly created thread.New in version 2.6.
applied_tags (
Sequence[abc.Snowflake]) –If in a forum/media channel and creating a new thread (see
thread_nameabove), the tags to apply to the new thread. Maximum of 5.New in version 2.10.
suppress_embeds (
bool) –Whether to suppress embeds for the message. This hides all the embeds from the UI if set to
True.New in version 2.5.
flags (
MessageFlags) –The flags to set for this message. Only
suppress_embedsandsuppress_notificationsare supported.If parameter
suppress_embedsis provided, that will override the setting ofMessageFlags.suppress_embeds.New in version 2.9.
wait (
bool) – Whether the server should wait before sending a response. This essentially means that the return type of this function changes fromNoneto aWebhookMessageif set toTrue.
- Raises:
HTTPException – Sending the message failed.
NotFound – This webhook was not found.
Forbidden – The authorization token for the webhook is incorrect.
TypeError – You specified both
embedandembedsorfileandfiles, or boththreadandthread_name/applied_tagswere provided.ValueError – The length of
embedswas invalidWebhookTokenMissing – There was no token associated with this webhook.
- Returns:
If
waitisTruethen the message that was sent, otherwiseNone.- Return type:
- fetch_message(id, /, *, thread=None)[source]¶
Retrieves a single
SyncWebhookMessageowned by this webhook.New in version 2.0.
Changed in version 2.6: Raises
WebhookTokenMissinginstead ofInvalidArgument.- Parameters:
- Raises:
NotFound – The specified message was not found.
Forbidden – You do not have the permissions required to get a message.
HTTPException – Retrieving the message failed.
WebhookTokenMissing – There was no token associated with this webhook.
- Returns:
The message asked for.
- Return type:
- edit_message(message_id, *, content=..., embed=..., embeds=..., file=..., files=..., attachments=..., allowed_mentions=None, thread=None)[source]¶
Edits a message owned by this webhook.
This is a lower level interface to
WebhookMessage.edit()in case you only have an ID.Note
If the original message has embeds with images that were created from local files (using the
fileparameter withEmbed.set_image()orEmbed.set_thumbnail()), those images will be removed if the message’s attachments are edited in any way (i.e. by settingfile/files/attachments, or adding an embed with local files).New in version 1.6.
Changed in version 2.6: Raises
WebhookTokenMissinginstead ofInvalidArgument.- Parameters:
message_id (
int) – The ID of the message to edit.content (
str|None) – The content to edit the message with, orNoneto clear it.embed (
Embed|None) – The new embed to replace the original with. This cannot be mixed with theembedsparameter. Could beNoneto remove the embed.embeds (
list[Embed]) – The new embeds to replace the original with. Must be a maximum of 10. This cannot be mixed with theembedparameter. To remove all embeds[]should be passed.file (
File) – The file to upload. This cannot be mixed with thefilesparameter. Files will be appended to the message, see theattachmentsparameter to remove/replace existing files.files (
list[File]) – A list of files to upload. This cannot be mixed with thefileparameter. Files will be appended to the message, see theattachmentsparameter to remove/replace existing files.attachments (
list[Attachment] |None) –A list of attachments to keep in the message. If
[]orNoneis passed then all existing attachments are removed. Keeps existing attachments if not provided.New in version 2.2.
Changed in version 2.5: Supports passing
Noneto clear attachments.allowed_mentions (
AllowedMentions) – Controls the mentions being processed in this message. Seeabc.Messageable.send()for more information.The thread the message is in, if any.
New in version 2.10.
- Raises:
HTTPException – Editing the message failed.
Forbidden – Edited a message that is not yours.
TypeError – You specified both
embedandembedsorfileandfilesValueError – The length of
embedswas invalidWebhookTokenMissing – There was no token associated with this webhook.
- delete_message(message_id, /, *, thread=None)[source]¶
Deletes a message owned by this webhook.
This is a lower level interface to
WebhookMessage.delete()in case you only have an ID.New in version 1.6.
Changed in version 2.6: Raises
WebhookTokenMissinginstead ofInvalidArgument.- Parameters:
- Raises:
HTTPException – Deleting the message failed.
Forbidden – Deleted a message that is not yours.
WebhookTokenMissing – There is no token associated with this webhook.
SyncWebhookMessage¶
- class disnake.SyncWebhookMessage[source]¶
Represents a message sent from your webhook.
This allows you to edit or delete a message sent by your webhook.
This inherits from
disnake.Messagewith changes toedit()anddelete()to work.New in version 2.0.
- edit(content=..., embed=..., embeds=..., file=..., files=..., attachments=..., allowed_mentions=None)[source]¶
Edits the message.
Note
If the original message has embeds with images that were created from local files (using the
fileparameter withEmbed.set_image()orEmbed.set_thumbnail()), those images will be removed if the message’s attachments are edited in any way (i.e. by settingfile/files/attachments, or adding an embed with local files).Changed in version 2.6: Raises
WebhookTokenMissinginstead ofInvalidArgument.- Parameters:
content (
str|None) – The content to edit the message with orNoneto clear it.embed (
Embed|None) – The new embed to replace the original with. This cannot be mixed with theembedsparameter. Could beNoneto remove the embed.embeds (
list[Embed]) – The new embeds to replace the original with. Must be a maximum of 10. This cannot be mixed with theembedparameter. To remove all embeds[]should be passed.file (
File) – The file to upload. This cannot be mixed with thefilesparameter. Files will be appended to the message, see theattachmentsparameter to remove/replace existing files.files (
list[File]) – A list of files to upload. This cannot be mixed with thefileparameter. Files will be appended to the message, see theattachmentsparameter to remove/replace existing files.attachments (
list[Attachment] |None) –A list of attachments to keep in the message. If
[]orNoneis passed then all existing attachments are removed. Keeps existing attachments if not provided.New in version 2.2.
Changed in version 2.5: Supports passing
Noneto clear attachments.allowed_mentions (
AllowedMentions) – Controls the mentions being processed in this message. Seeabc.Messageable.send()for more information.
- Raises:
HTTPException – Editing the message failed.
Forbidden – Edited a message that is not yours.
TypeError – You specified both
embedandembedsorfileandfilesValueError – The length of
embedswas invalidWebhookTokenMissing – There is no token associated with this webhook.
- Returns:
The newly edited message.
- Return type:
- delete(*, delay=None)[source]¶
Deletes the message.
Changed in version 2.6: Raises
WebhookTokenMissinginstead ofInvalidArgument.- Parameters:
delay (
float|None) – If provided, the number of seconds to wait before deleting the message. This blocks the thread.- Raises:
Forbidden – You do not have proper permissions to delete the message.
NotFound – The message was deleted already.
HTTPException – Deleting the message failed.
WebhookTokenMissing – There is no token associated with this webhook.
PartialWebhookGuild¶
PartialWebhookChannel¶
Enumerations¶
WebhookType¶
- class disnake.WebhookType[source]¶
Represents the type of webhook that can be received.
New in version 1.3.
- incoming¶
Represents a webhook that can post messages to channels with a token.
- channel_follower¶
Represents a webhook that is internally managed by Discord, used for following channels.
- application¶
Represents a webhook that is used for interactions or applications.
New in version 2.0.