Messages¶
This section documents everything related to Discord messages.
Discord Models¶
Message¶
- activity
- application
- application_id
- attachments
- author
- call
- channel
- channel_mentions
- clean_content
- components
- content
- created_at
- edited_at
- embeds
- flags
- guild
- id
- interaction
- interaction_metadata
- jump_url
- mention_everyone
- mentions
- message_snapshots
- nonce
- pinned
- pinned_at
- poll
- position
- raw_channel_mentions
- raw_mentions
- raw_role_mentions
- reactions
- reference
- role_mentions
- role_subscription_data
- stickers
- system_content
- thread
- tts
- type
- webhook_id
- asyncadd_reaction
- asyncclear_reaction
- asyncclear_reactions
- asynccreate_thread
- asyncdelete
- asyncedit
- asyncforward
- defis_system
- asyncpin
- asyncpublish
- asyncremove_reaction
- asyncreply
- defto_reference
- asyncunpin
- class disnake.Message[source]¶
Represents a message from Discord.
- x == y
Checks if two messages are equal.
- x != y
Checks if two messages are not equal.
- hash(x)
Returns the message’s hash.
- tts¶
Specifies if the message was done with text-to-speech. This can only be accurately received in
on_message()due to a Discord limitation.- Type:
- type¶
The type of message. In most cases this should not be checked, but it is helpful in cases where it might be a system message for
system_content.- Type:
- author¶
A
Memberthat sent the message. Ifchannelis a private channel or the user has the left the guild, then it is aUserinstead.
- nonce¶
The value used by the Discord guild and the client to verify that the message is successfully sent. This is not stored long term within Discord’s servers and is only used ephemerally.
- channel¶
The channel that the message was sent from. Could be a
DMChannelorGroupChannelif it’s a private message.- Type:
TextChannel|VoiceChannel|StageChannel|Thread|DMChannel|GroupChannel|PartialMessageable
- position¶
A number that indicates the approximate position of a message in a
Thread. This is a number that starts at 0. e.g. the first message is position 0. This isNoneif the message was not sent in aThread, or if it was sent before July 1, 2022.New in version 2.6.
- reference¶
The message that this message references. This is only applicable to messages of type
MessageType.pins_add, crossposted messages created by a followed channel integration, message replies, or application command responses.New in version 1.5.
- Type:
- interaction_metadata¶
The metadata about the interaction that caused this message, if any.
New in version 2.10.
- Type:
- mention_everyone¶
Specifies if the message mentions everyone.
Note
This does not check if the
@everyoneor the@heretext is in the message itself. Rather this boolean indicates if either the@everyoneor the@heretext is in the message and it did end up mentioning.- Type:
- mentions¶
A list of
Memberthat were mentioned. If the message is in a private message then the list will be ofUserinstead. For messages that are not of typeMessageType.default, this array can be used to aid in system messages. For more information, seesystem_content.Warning
The order of the mentions list is not in any particular order so you should not rely on it. This is a Discord limitation, not one with the library.
- role_mentions¶
A list of
Rolethat were mentioned. If the message is in a private message then the list is always empty.
- application_id¶
If this message was sent from an interaction, or is an application owned webhook, then this is the ID of the application.
New in version 2.5.
- webhook_id¶
If this message was sent by a webhook, then this is the webhook ID’s that sent this message.
- attachments¶
A list of attachments given to a message.
- Type:
- flags¶
Extra features of the message.
New in version 1.3.
- Type:
- reactions¶
Reactions to a message. Reactions can be either custom emoji or standard unicode emoji.
- activity¶
The activity associated with this message. Sent with Rich-Presence related messages that for example, request joining, spectating, or listening to or with another member.
It is a dictionary with the following optional keys:
type: An integer denoting the type of message activity being requested.party_id: The party ID associated with the party.
- application¶
The rich presence enabled application associated with this message.
It is a dictionary with the following keys:
id: A string representing the application’s ID.name: A string representing the application’s name.description: A string representing the application’s description.icon: A string representing the icon ID of the application.cover_image: A string representing the embed’s image asset ID.
- stickers¶
A list of sticker items given to the message.
New in version 1.6.
- Type:
- message_snapshots¶
A list of forwarded messages.
New in version 2.10.
- Type:
- call¶
The call contained in this message. Only present when
typeisMessageType.call.New in version 2.12.
- Type:
- raw_mentions¶
A property that returns an array of user IDs matched with the syntax of
<@user_id>in the message content.This allows you to receive the user IDs of mentioned users even in a private message context.
- raw_channel_mentions¶
A property that returns an array of channel IDs matched with the syntax of
<#channel_id>in the message content.
- raw_role_mentions¶
A property that returns an array of role IDs matched with the syntax of
<@&role_id>in the message content.
- channel_mentions¶
A list of
abc.GuildChannelthat were mentioned. If the message is in a private message then the list is always empty.- Type:
- clean_content¶
A property that returns the content in a “cleaned up” manner. This basically means that mentions are transformed into the way the client shows it. e.g.
<#id>will transform into#name.This will also transform @everyone and @here mentions into non-mentions.
Note
This does not affect markdown. If you want to escape or remove markdown then use
utils.escape_markdown()orutils.remove_markdown()respectively, along with this function.- Type:
- property edited_at[source]¶
An aware UTC datetime object containing the edited time of the message.
- Type:
- property pinned_at[source]¶
An aware UTC datetime object containing the pin time of the message.
Note
This is only set on messages retrieved using
abc.Messageable.pins().New in version 2.11.
- Type:
- property thread[source]¶
The thread started from this message.
Noneif no thread has been started.New in version 2.4.
- property role_subscription_data[source]¶
The metadata of the role subscription purchase/renewal, if this message is a
MessageType.role_subscription_purchase.New in version 2.9.
- Type:
- is_system()[source]¶
Whether the message is a system message.
A system message is a message that is constructed entirely by the Discord API in response to something.
New in version 1.3.
- Return type:
- system_content¶
A property that returns the content that is rendered regardless of the
Message.type.In the case of
MessageType.defaultandMessageType.reply, this just returns the regularMessage.content. Otherwise this returns an English message denoting the contents of the system message.If the message type is unrecognised this method will return
None.
- property interaction[source]¶
The interaction that this message references. This exists only when the message is a response to an interaction without an existing message.
New in version 2.1.
Deprecated since version 2.10: Use
interaction_metadatainstead.- Type:
- await delete(*, delay=None)[source]¶
This function is a coroutine.
Deletes the message.
Your own messages could be deleted without any proper permissions. However to delete other people’s messages, you need the
manage_messagespermission.Changed in version 1.1: Added the new
delaykeyword-only parameter.- Parameters:
delay (
float|None) – If provided, the number of seconds to wait in the background before deleting the message. If the deletion fails then it is silently ignored.- Raises:
Forbidden – You do not have proper permissions to delete the message.
NotFound – The message was deleted already
HTTPException – Deleting the message failed.
- await edit(content=..., *, embed=..., embeds=..., file=..., files=..., attachments=..., suppress=..., suppress_embeds=..., flags=..., allowed_mentions=..., view=..., components=..., delete_after=None)[source]¶
This function is a coroutine.
Edits the message.
The content must be able to be transformed into a string via
str(content).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).Note
This method cannot be used on messages authored by others, with one exception. The
suppress_embedsparameter can be used to change the state of embeds on other users’ messages, requiring themanage_messagespermission.Changed in version 1.3: The
suppresskeyword-only parameter was added.Changed in version 2.5: The
suppresskeyword-only parameter was deprecated in favor ofsuppress_embeds.Changed in version 2.6: Raises
TypeErrorinstead ofInvalidArgument.- Parameters:
content (
str|None) – The new content to replace the message with. Could beNoneto remove the content.embed (
Embed|None) – The new embed to replace the original with. This cannot be mixed with theembedsparameter. Could beNoneto remove the embed.The new embeds to replace the original with. Must be a maximum of 10. This cannot be mixed with the
embedparameter. To remove all embeds[]should be passed.New in version 2.0.
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.1.
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.1.
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.Changed in version 2.5: Supports passing
Noneto clear attachments.suppress_embeds (
bool) – Whether to suppress embeds for the message. This hides all the embeds from the UI if set toTrue. If set toFalse, this brings the embeds back if they were suppressed.flags (
MessageFlags) –The new flags to set for this message. Overrides existing flags. Only
suppress_embedsandis_components_v2are supported.If parameter
suppress_embedsis provided, that will override the setting ofMessageFlags.suppress_embeds.New in version 2.9.
delete_after (
float|None) – If provided, the number of seconds to wait in the background before deleting the message we just edited. If the deletion fails, then it is silently ignored.allowed_mentions (
AllowedMentions|None) –Controls the mentions being processed in this message. If this is passed, then the object is merged with
Client.allowed_mentions. 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.
The updated 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]]) –The updated 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.
- Raises:
HTTPException – Editing the message failed.
Forbidden – Tried to suppress embeds on a message without permissions or edited a message’s content or embed that isn’t yours.
TypeError – You specified both
embedandembeds, orfileandfiles, orviewandcomponents.ValueError – You tried to send v2 components together with
contentorembeds.
- Returns:
The message that was edited.
- Return type:
- await publish()[source]¶
This function is a coroutine.
Publishes this message to your announcement channel.
You must have the
send_messagespermission to do this.If the message is not your own then the
manage_messagespermission is also needed.- Raises:
Forbidden – You do not have the proper permissions to publish this message.
HTTPException – Publishing the message failed.
- await pin(*, reason=None)[source]¶
This function is a coroutine.
Pins the message.
You must have the
pin_messagespermission to do this in a non-private channel context.This does not work with messages sent in a
VoiceChannelorStageChannel.- Parameters:
The reason for pinning the message. Shows up on the audit log.
New in version 1.4.
- Raises:
Forbidden – You do not have permissions to pin the message.
NotFound – The message or channel was not found or deleted.
HTTPException – Pinning the message failed, probably due to the channel having more than 50 pinned messages or the channel not supporting pins.
- await unpin(*, reason=None)[source]¶
This function is a coroutine.
Unpins the message.
You must have the
pin_messagespermission to do this in a non-private channel context.- Parameters:
The reason for unpinning the message. Shows up on the audit log.
New in version 1.4.
- Raises:
Forbidden – You do not have permissions to unpin the message.
NotFound – The message or channel was not found or deleted.
HTTPException – Unpinning the message failed.
- await add_reaction(emoji)[source]¶
This function is a coroutine.
Adds a reaction to the message.
The emoji may be a unicode emoji or a custom guild
Emoji.You must have the
read_message_historypermission to use this. If nobody else has reacted to the message using this emoji, theadd_reactionspermission is required.Changed in version 2.6: Raises
TypeErrorinstead ofInvalidArgument.- Parameters:
emoji (
Emoji|Reaction|PartialEmoji|str) – The emoji to react with.- Raises:
HTTPException – Adding the reaction failed.
Forbidden – You do not have the proper permissions to react to the message.
NotFound – The emoji you specified was not found.
TypeError – The emoji parameter is invalid.
- await remove_reaction(emoji, member)[source]¶
This function is a coroutine.
Removes a reaction by the member from the message.
The emoji may be a unicode emoji or a custom guild
Emoji.If the reaction is not your own (i.e.
memberparameter is not you) then themanage_messagespermission is needed.The
memberparameter must represent a member and meet theabc.Snowflakeabc.Changed in version 2.6: Raises
TypeErrorinstead ofInvalidArgument.- Parameters:
emoji (
Emoji|Reaction|PartialEmoji|str) – The emoji to remove.member (
abc.Snowflake) – The member for which to remove the reaction.
- Raises:
HTTPException – Removing the reaction failed.
Forbidden – You do not have the proper permissions to remove the reaction.
NotFound – The member or emoji you specified was not found.
TypeError – The emoji parameter is invalid.
- await clear_reaction(emoji)[source]¶
This function is a coroutine.
Clears a specific reaction from the message.
The emoji may be a unicode emoji or a custom guild
Emoji.You need the
manage_messagespermission to use this.New in version 1.3.
Changed in version 2.6: Raises
TypeErrorinstead ofInvalidArgument.- Parameters:
emoji (
Emoji|Reaction|PartialEmoji|str) – The emoji to clear.- Raises:
HTTPException – Clearing the reaction failed.
Forbidden – You do not have the proper permissions to clear the reaction.
NotFound – The emoji you specified was not found.
TypeError – The emoji parameter is invalid.
- await clear_reactions()[source]¶
This function is a coroutine.
Removes all the reactions from the message.
You need the
manage_messagespermission to use this.- Raises:
HTTPException – Removing the reactions failed.
Forbidden – You do not have the proper permissions to remove all the reactions.
- await create_thread(*, name, auto_archive_duration=None, slowmode_delay=None, reason=None)[source]¶
This function is a coroutine.
Creates a public thread from this message.
You must have
create_public_threadsin order to create a public thread from a message.The channel this message belongs in must be a
TextChannel.New in version 2.0.
Changed in version 2.6: Raises
TypeErrorinstead ofInvalidArgument.- Parameters:
name (
str) – The name of the thread.auto_archive_duration (
int|ThreadArchiveDuration) – The duration in minutes before a thread is automatically archived for inactivity. If not provided, the channel’s default auto archive duration is used. Must be one of60,1440,4320, or10080.Specifies the slowmode rate limit for users in this thread, in seconds. A value of
0disables slowmode. The maximum value possible is21600. If set toNoneor not provided, slowmode is inherited from the parent’sdefault_thread_slowmode_delay.New in version 2.3.
The reason for creating the thread. Shows up on the audit log.
New in version 2.5.
- Raises:
Forbidden – You do not have permissions to create a thread.
HTTPException – Creating the thread failed.
TypeError – This message does not have guild info attached.
- Returns:
The created thread.
- Return type:
- await reply(content=None, *, fail_if_not_exists=True, **kwargs)[source]¶
This function is a coroutine.
A shortcut method to
abc.Messageable.send()to reply to theMessage.New in version 1.6.
Changed in version 2.3: Added
fail_if_not_existskeyword argument. Defaults toTrue.Changed in version 2.6: Raises
TypeErrororValueErrorinstead ofInvalidArgument.- Parameters:
fail_if_not_exists (
bool) –Whether replying using the message reference should raise
HTTPExceptionif the message no longer exists or Discord could not fetch the message.New in version 2.3.
- Raises:
HTTPException – Sending the message failed.
Forbidden – You do not have the proper permissions to send the message.
TypeError – You specified both
embedandembeds, orfileandfiles, orviewandcomponents.ValueError – The
filesorembedslist is too large.
- Returns:
The message that was sent.
- Return type:
- await forward(channel)[source]¶
This function is a coroutine.
A shortcut method to
abc.Messageable.send()to forward aMessage.New in version 2.10.
- Parameters:
channel (
TextChannel|VoiceChannel|StageChannel|Thread|DMChannel|GroupChannel|PartialMessageable) – The channel where the message should be forwarded to.- Raises:
HTTPException – Sending the message failed.
Forbidden – You do not have the proper permissions to send the message.
- Returns:
The message that was sent.
- Return type:
- to_reference(*, type=MessageReferenceType.default, fail_if_not_exists=True)[source]¶
Creates a
MessageReferencefrom the current message.New in version 1.6.
- Parameters:
type (
MessageReferenceType) –The type of the message reference. This is used to control whether to reply to or forward a message. Defaults to replying.
New in version 2.10.
fail_if_not_exists (
bool) –Whether replying using the message reference should raise
HTTPExceptionif the message no longer exists or Discord could not fetch the message.New in version 1.7.
- Returns:
The reference to this message.
- Return type:
Reaction¶
- class disnake.Reaction[source]¶
Represents a reaction to a message.
Depending on the way this object was created, some of the attributes can have a value of
None.- x == y
Checks if two reactions are equal. This works by checking if the emoji is the same. So two messages with the same reaction will be considered “equal”.
- x != y
Checks if two reactions are not equal.
- hash(x)
Returns the reaction’s hash.
- str(x)
Returns the string form of the reaction’s emoji.
- emoji¶
The reaction emoji. May be a custom emoji, or a unicode emoji.
- Type:
Emoji|PartialEmoji|str
- async for ... in users(*, limit=None, after=None)[source]¶
Returns an
AsyncIteratorrepresenting the users that have reacted to the message.The
afterparameter must represent a member and meet theabc.Snowflakeabc.Examples
Usage
# We do not actually recommend doing this. async for user in reaction.users(): await channel.send(f'{user} has reacted with {reaction.emoji}!')
Flattening into a list:
users = await reaction.users().flatten() # users is now a list of User... winner = random.choice(users) await channel.send(f'{winner} has won the raffle.')
- Parameters:
limit (
int|None) – The maximum number of results to return. If not provided, returns all the users who reacted to the message.after (
abc.Snowflake|None) – For pagination, reactions are sorted by member.
- Raises:
HTTPException – Getting the users for the reaction failed.
- Yields:
User|Member– The member (if retrievable) or the user that has reacted to this message. The case where it can be aMemberis in a guild message context. Sometimes it can be aUserif the member has left the guild.
- await remove(user)[source]¶
This function is a coroutine.
Removes the reaction by the provided
Userfrom the message.If the reaction is not your own (i.e.
userparameter is not you) then themanage_messagespermission is needed.The
userparameter must represent a user or member and meet theabc.Snowflakeabc.- Parameters:
user (
abc.Snowflake) – The user or member from which to remove the reaction.- Raises:
HTTPException – Removing the reaction failed.
Forbidden – You do not have the proper permissions to remove the reaction.
NotFound – The user you specified, or the reaction’s message was not found.
- await clear()[source]¶
This function is a coroutine.
Clears this reaction from the message.
You need the
manage_messagespermission to use this.New in version 1.3.
Changed in version 2.6: Raises
TypeErrorinstead ofInvalidArgument.- Raises:
HTTPException – Clearing the reaction failed.
Forbidden – You do not have the proper permissions to clear the reaction.
NotFound – The emoji you specified was not found.
TypeError – The emoji parameter is invalid.
Attachment¶
- defis_spoiler
- asyncread
- asyncsave
- asyncto_file
- class disnake.Attachment[source]¶
Represents an attachment from Discord.
- str(x)
Returns the URL of the attachment.
- x == y
Checks if the attachment is equal to another attachment.
- x != y
Checks if the attachment is not equal to another attachment.
- hash(x)
Returns the hash of the attachment.
Changed in version 1.7: Attachment can now be casted to
strand is hashable.- title¶
The attachment title. If the filename contained special characters, this will be set to the original filename, without filename extension.
New in version 2.10.
- url¶
The attachment URL. If the message this attachment was attached to is deleted, then this will 404.
- Type:
- proxy_url¶
The proxy URL. This is a cached version of the
urlin the case of images. When the message is deleted, this URL might be valid for a few minutes or not valid at all.- Type:
- content_type¶
The attachment’s media type.
New in version 1.7.
- duration¶
The duration of the audio attachment in seconds, if this is attached to a voice message (see
MessageFlags.is_voice_message).New in version 2.9.
- waveform¶
The byte array representing a sampled waveform, if this is attached to a voice message (see
MessageFlags.is_voice_message).New in version 2.9.
- await save(fp, *, seek_begin=True, use_cached=False)[source]¶
This function is a coroutine.
Saves this attachment into a file-like object.
- Parameters:
fp (
io.BufferedIOBase|os.PathLike) – The file-like object to save this attachment to or the filename to use. If a filename is passed then a file is created with that filename and used instead.seek_begin (
bool) – Whether to seek to the beginning of the file after saving is successfully done.use_cached (
bool) – Whether to useproxy_urlrather thanurlwhen downloading the attachment. This will allow attachments to be saved after deletion more often, compared to the regular URL which is generally deleted right after the message is deleted. Note that this can still fail to download deleted attachments if too much time has passed and it does not work on some types of attachments.
- Raises:
HTTPException – Saving the attachment failed.
NotFound – The attachment was deleted.
- Returns:
The number of bytes written.
- Return type:
- await read(*, use_cached=False)[source]¶
This function is a coroutine.
Retrieves the content of this attachment as a
bytesobject.New in version 1.1.
- Parameters:
use_cached (
bool) – Whether to useproxy_urlrather thanurlwhen downloading the attachment. This will allow attachments to be saved after deletion more often, compared to the regular URL which is generally deleted right after the message is deleted. Note that this can still fail to download deleted attachments if too much time has passed and it does not work on some types of attachments.- Raises:
HTTPException – Downloading the attachment failed.
Forbidden – You do not have permissions to access this attachment
NotFound – The attachment was deleted.
- Returns:
The contents of the attachment.
- Return type:
- await to_file(*, use_cached=False, spoiler=False, description=...)[source]¶
This function is a coroutine.
Converts the attachment into a
Filesuitable for sending viaabc.Messageable.send().New in version 1.3.
- Parameters:
use_cached (
bool) –Whether to use
proxy_urlrather thanurlwhen downloading the attachment. This will allow attachments to be saved after deletion more often, compared to the regular URL which is generally deleted right after the message is deleted. Note that this can still fail to download deleted attachments if too much time has passed and it does not work on some types of attachments.New in version 1.4.
spoiler (
bool) –Whether the file is a spoiler.
New in version 1.4.
The file’s description. Copies this attachment’s description by default, set to
Noneto remove.New in version 2.3.
- Raises:
HTTPException – Downloading the attachment failed.
Forbidden – You do not have permissions to access this attachment
NotFound – The attachment was deleted.
- Returns:
The attachment as a file suitable for sending.
- Return type:
DeletedReferencedMessage¶
- class disnake.DeletedReferencedMessage[source]¶
A special sentinel type that denotes whether the resolved message referenced message had since been deleted.
The purpose of this class is to separate referenced messages that could not be fetched and those that were previously fetched but have since been deleted.
New in version 1.6.
InteractionReference¶
- class disnake.InteractionReference[source]¶
Represents an interaction being referenced in a message.
This means responses to message components do not include this property, instead including a message reference object as components always exist on preexisting messages.
New in version 2.1.
Deprecated since version 2.10: Use
Message.interaction_metadatainstead.- type¶
The type of interaction.
- Type:
- name¶
The name of the application command, including group and subcommand name if applicable (separated by spaces).
Note
For interaction references created before July 18th, 2022, this will not include group or subcommand names.
- Type:
InteractionMetadata¶
- class disnake.InteractionMetadata[source]¶
Represents metadata about the interaction that caused a particular message.
New in version 2.10.
- type¶
The type of the interaction.
- Type:
- authorizing_integration_owners¶
Details about the authorizing user/guild for the application installation related to the interaction.
- original_response_message_id¶
The ID of the original response message. Only present on
followupmessages.
- target_user¶
The ID of the message the command was run on. Only present on interactions of
ApplicationCommandType.messagecommands.
- target_message_id¶
The user the command was run on. Only present on interactions of
ApplicationCommandType.usercommands.
- interacted_message_id¶
The ID of the message containing the component. Only present on
InteractionType.componentinteractions.
- triggering_interaction_metadata¶
The metadata of the original interaction that triggered the modal. Only present on
InteractionType.modal_submitinteractions.- Type:
RoleSubscriptionData¶
- class disnake.RoleSubscriptionData[source]¶
Represents metadata of the role subscription purchase/renewal in a message of type
MessageType.role_subscription_purchase.New in version 2.9.
- role_subscription_listing_id¶
The ID of the subscription listing the user subscribed to.
See also
RoleTags.subscription_listing_id.- Type:
- total_months_subscribed¶
The cumulative number of months the user has been subscribed for.
- Type:
MessageCall¶
RawTypingEvent¶
- class disnake.RawTypingEvent[source]¶
Represents the event payload for an
on_raw_typing()event.New in version 2.3.
- timestamp¶
The UTC datetime when the user started typing.
Changed in version 2.9: Changed from naive to aware datetime.
- Type:
RawMessageDeleteEvent¶
- class disnake.RawMessageDeleteEvent[source]¶
Represents the event payload for an
on_raw_message_delete()event.
RawBulkMessageDeleteEvent¶
- class disnake.RawBulkMessageDeleteEvent[source]¶
Represents the event payload for an
on_raw_bulk_message_delete()event.
RawMessageUpdateEvent¶
- class disnake.RawMessageUpdateEvent[source]¶
Represents the event payload for an
on_raw_message_edit()event.- guild_id¶
The guild ID where the update took place, if applicable.
New in version 1.7.
- cached_message¶
The cached message, if found in the internal message cache. Represents the message before it is modified by the data in
RawMessageUpdateEvent.data.
RawPollVoteActionEvent¶
- class disnake.RawPollVoteActionEvent[source]¶
Represents the event payload for
on_raw_poll_vote_add()andon_raw_poll_vote_remove()events.New in version 2.10.
- cached_member¶
The member who added the vote. Available only when the guilds and members are cached.
- guild_id¶
The guild ID where the vote addition or removal took place, if applicable.
RawReactionActionEvent¶
- class disnake.RawReactionActionEvent[source]¶
Represents the event payload for
on_raw_reaction_add()andon_raw_reaction_remove()events.- guild_id¶
The guild ID where the reaction addition or removal took place, if applicable.
- emoji¶
The custom or unicode emoji being used.
Changed in version 2.9: This now also includes the correct
animatedvalue when a reaction was removed.- Type:
- member¶
The member who added the reaction. Only available if
event_typeisREACTION_ADDand the reaction is inside a guild.New in version 1.3.
- event_type¶
The event type that triggered this action. Can be
REACTION_ADDfor reaction addition orREACTION_REMOVEfor reaction removal.New in version 1.3.
- Type:
- message_author_id¶
The ID of the author who created the message that got a reaction. Only available if
event_typeisREACTION_ADD. May also beNoneif the message was created by a webhook.New in version 2.10.
RawReactionClearEvent¶
- class disnake.RawReactionClearEvent[source]¶
Represents the event payload for an
on_raw_reaction_clear()event.
RawReactionClearEmojiEvent¶
- class disnake.RawReactionClearEmojiEvent[source]¶
Represents the event payload for an
on_raw_reaction_clear_emoji()event.New in version 1.3.
Data Classes¶
Embed¶
- clsEmbed.from_dict
- clsEmbed.get_default_color
- clsEmbed.get_default_colour
- clsEmbed.set_default_color
- clsEmbed.set_default_colour
- defadd_field
- defcheck_limits
- defclear_fields
- defcopy
- definsert_field_at
- defremove_author
- defremove_field
- defremove_footer
- defset_author
- defset_field_at
- defset_footer
- defset_image
- defset_thumbnail
- defto_dict
- class disnake.Embed(*, title=None, type='rich', description=None, url=None, timestamp=None, colour=..., color=...)[source]¶
Represents a Discord embed.
- x == y
Checks if two embeds are equal.
New in version 2.6.
- x != y
Checks if two embeds are not equal.
New in version 2.6.
- len(x)
Returns the total size of the embed. Useful for checking if it’s within the 6000 character limit. Check if all aspects of the embed are within the limits with
Embed.check_limits().
- bool(b)
Returns whether the embed has any data set.
New in version 2.0.
Certain properties return an
EmbedProxy, a type that acts similar to a regulardictexcept using dotted access, e.g.embed.author.icon_url.For ease of use, all parameters that expect a
strare implicitly cast tostrfor you.- type¶
The type of embed. Usually “rich”. Possible strings for embed types can be found on Discord’s api-docs.
- timestamp[source]¶
The timestamp of the embed content. This is an aware datetime. If a naive datetime is passed, it is converted to an aware datetime with the local timezone.
- Type:
- colour[source]¶
The colour code of the embed. Aliased to
coloras well. In addition toColour,intcan also be assigned to it, in which case the value will be converted to aColourobject.
- classmethod from_dict(data)[source]¶
Converts a
dictto aEmbedprovided it is in the format that Discord expects it to be in.You can find out about this format in the official Discord documentation.
- Parameters:
data (
dict) – The dictionary to convert into an embed.
Returns an
EmbedProxydenoting the footer contents.Possible attributes you can access are:
texticon_urlproxy_icon_url
If an attribute is not set, it will be
None.
Sets the footer for the embed content.
This function returns the class instance to allow for fluent-style chaining.
At most one of
icon_urloricon_filemay be passed.Warning
Passing a
disnake.Fileobject will make the embed not reusable.Warning
If used with the other
set_*methods, you must ensure that theFile.filenameis unique to avoid duplication.
Clears embed’s footer information.
This function returns the class instance to allow for fluent-style chaining.
New in version 2.0.
- property image[source]¶
Returns an
EmbedProxydenoting the image contents.Possible attributes you can access are:
urlproxy_urlwidthheight
If an attribute is not set, it will be
None.
- set_image(url=..., *, file=...)[source]¶
Sets the image for the embed content.
This function returns the class instance to allow for fluent-style chaining.
Exactly one of
urlorfilemust be passed.Warning
Passing a
disnake.Fileobject will make the embed not reusable.Warning
If used with the other
set_*methods, you must ensure that theFile.filenameis unique to avoid duplication.Changed in version 1.4: Passing
Noneremoves the image.
- property thumbnail[source]¶
Returns an
EmbedProxydenoting the thumbnail contents.Possible attributes you can access are:
urlproxy_urlwidthheight
If an attribute is not set, it will be
None.
- set_thumbnail(url=..., *, file=...)[source]¶
Sets the thumbnail for the embed content.
This function returns the class instance to allow for fluent-style chaining.
Exactly one of
urlorfilemust be passed.Warning
Passing a
disnake.Fileobject will make the embed not reusable.Warning
If used with the other
set_*methods, you must ensure that theFile.filenameis unique to avoid duplication.Changed in version 1.4: Passing
Noneremoves the thumbnail.
- property video[source]¶
Returns an
EmbedProxydenoting the video contents.Possible attributes include:
urlfor the video URL.proxy_urlfor the proxied video URL.heightfor the video height.widthfor the video width.
If an attribute is not set, it will be
None.
- property provider[source]¶
Returns an
EmbedProxydenoting the provider contents.The only attributes that might be accessed are
nameandurl.If an attribute is not set, it will be
None.
- property author[source]¶
Returns an
EmbedProxydenoting the author contents.See
set_author()for possible values you can access.If an attribute is not set, it will be
None.
- set_author(*, name, url=None, icon_url=..., icon_file=...)[source]¶
Sets the author for the embed content.
This function returns the class instance to allow for fluent-style chaining.
At most one of
icon_urloricon_filemay be passed.Warning
Passing a
disnake.Fileobject will make the embed not reusable.Warning
If used with the other
set_*methods, you must ensure that theFile.filenameis unique to avoid duplication.
- remove_author()[source]¶
Clears embed’s author information.
This function returns the class instance to allow for fluent-style chaining.
New in version 1.4.
- property fields[source]¶
Returns a
listofEmbedProxydenoting the field contents.See
add_field()for possible values you can access.If an attribute is not set, it will be
None.- Type:
list[EmbedProxy]
- add_field(name, value, *, inline=True)[source]¶
Adds a field to the embed object.
This function returns the class instance to allow for fluent-style chaining.
- insert_field_at(index, name, value, *, inline=True)[source]¶
Inserts a field before a specified index to the embed.
This function returns the class instance to allow for fluent-style chaining.
New in version 1.2.
- remove_field(index)[source]¶
Removes a field at a specified index.
If the index is invalid or out of bounds then the error is silently swallowed.
Note
When deleting a field by index, the index of the other fields shift to fill the gap just like a regular list.
- Parameters:
index (
int) – The index of the field to remove.
- set_field_at(index, name, value, *, inline=True)[source]¶
Modifies a field to the embed object.
The index must point to a valid pre-existing field.
This function returns the class instance to allow for fluent-style chaining.
- Parameters:
- Raises:
IndexError – An invalid index was provided.
- classmethod set_default_colour(value)[source]¶
Set the default colour of all new embeds.
New in version 2.4.
- classmethod set_default_color(value)[source]¶
Set the default colour of all new embeds.
New in version 2.4.
- classmethod get_default_colour()[source]¶
Get the default colour of all new embeds.
New in version 2.4.
- classmethod get_default_color()[source]¶
Get the default colour of all new embeds.
New in version 2.4.
- check_limits()[source]¶
Checks if this embed fits within the limits dictated by Discord. There is also a 6000 character limit across all embeds in a message.
Returns nothing on success, raises
ValueErrorif an attribute exceeds the limits.Field
Limit
title
256 characters
description
4096 characters
fields
Up to 25 field objects
field.name
256 characters
field.value
1024 characters
footer.text
2048 characters
author.name
256 characters
New in version 2.6.
- Raises:
ValueError – One or more of the embed attributes are too long.
File¶
- class disnake.File(fp, filename=None, *, spoiler=False, description=None)[source]¶
A parameter object used for sending file objects.
Note
File objects are single use and are not meant to be reused in multiple
abc.Messageable.send(),Message.edit(),Interaction.send(), orInteraction.edit_original_response()calls or similar methods.- fp¶
A file-like object opened in binary mode and read mode or a filename representing a file in the hard drive to open.
Note
If the file-like object passed is opened via
openthen the modes ‘rb’ should be used.To pass binary data, consider usage of
io.BytesIO.- Type:
- filename¶
The filename to display when uploading to Discord. If this is not given then it defaults to
fp.nameor iffpis a string then thefilenamewill default to the string given.
MessageFlags¶
- class disnake.MessageFlags[source]¶
Wraps up a Discord Message flag value.
See
SystemChannelFlags.- x == y
Checks if two MessageFlags instances are equal.
- x != y
Checks if two MessageFlags instances are not equal.
- x <= y
Checks if a MessageFlags instance is a subset of another MessageFlags instance.
New in version 2.6.
- x >= y
Checks if a MessageFlags instance is a superset of another MessageFlags instance.
New in version 2.6.
- x < y
Checks if a MessageFlags instance is a strict subset of another MessageFlags instance.
New in version 2.6.
- x > y
Checks if a MessageFlags instance is a strict superset of another MessageFlags instance.
New in version 2.6.
- x | y, x |= y
Returns a new MessageFlags instance with all enabled flags from both x and y. (Using
|=will update in place).New in version 2.6.
- x & y, x &= y
Returns a new MessageFlags instance with only flags enabled on both x and y. (Using
&=will update in place).New in version 2.6.
- x ^ y, x ^= y
Returns a new MessageFlags instance with only flags enabled on one of x or y, but not both. (Using
^=will update in place).New in version 2.6.
- ~x
Returns a new MessageFlags instance with all flags from x inverted.
New in version 2.6.
- hash(x)
Return the flag’s hash.
- iter(x)
Returns an iterator of
(name, value)pairs. This allows it to be, for example, constructed as a dict or a list of pairs.
Additionally supported are a few operations on class attributes.
- MessageFlags.y | MessageFlags.z, MessageFlags(y=True) | MessageFlags.z
Returns a MessageFlags instance with all provided flags enabled.
New in version 2.6.
- ~MessageFlags.y
Returns a MessageFlags instance with all flags except
yinverted from their default value.New in version 2.6.
New in version 1.3.
- value¶
The raw value. This value is a bit array field of a 53-bit integer representing the currently available flags. You should query flags via the properties rather than using this raw value.
- Type:
- source_message_deleted¶
Returns
Trueif the source message for this crosspost has been deleted.- Type:
- urgent¶
Returns
Trueif the message is an urgent message.An urgent message is one sent by Discord Trust and Safety.
- Type:
- loading¶
Returns
Trueif the message is a deferred interaction response and shows a “thinking” state.New in version 2.3.
- Type:
- failed_to_mention_roles_in_thread¶
Returns
Trueif the message failed to mention some roles and add their members to the thread.New in version 2.4.
- Type:
- suppress_notifications¶
Returns
Trueif the message does not trigger push and desktop notifications.New in version 2.9.
- Type:
- is_voice_message¶
Returns
Trueif the message is a voice message.Messages with this flag will have a single audio attachment, and no other content.
New in version 2.9.
- Type:
- has_snapshot¶
Returns
Trueif the message is a forward message.Messages with this flag will have only the forward data, and no other content.
New in version 2.10.
- Type:
- is_components_v2¶
Returns
Trueif the message uses the Components V2 system.Messages with this flag will use specific components for content layout, instead of
contentandembeds. Further details, limits, and example images can be found in the API documentation.Note that once this flag is set on a message, it cannot be reverted.
New in version 2.11.
- Type:
AttachmentFlags¶
- class disnake.AttachmentFlags[source]¶
Wraps up Discord Attachment flags.
- x == y
Checks if two AttachmentFlags instances are equal.
- x != y
Checks if two AttachmentFlags instances are not equal.
- x <= y
Checks if an AttachmentFlags instance is a subset of another AttachmentFlags instance.
- x >= y
Checks if an AttachmentFlags instance is a superset of another AttachmentFlags instance.
- x < y
Checks if an AttachmentFlags instance is a strict subset of another AttachmentFlags instance.
- x > y
Checks if an AttachmentFlags instance is a strict superset of another AttachmentFlags instance.
- x | y, x |= y
Returns a new AttachmentFlags instance with all enabled flags from both x and y. (Using
|=will update in place).
- x & y, x &= y
Returns a new AttachmentFlags instance with only flags enabled on both x and y. (Using
&=will update in place).
- x ^ y, x ^= y
Returns a new AttachmentFlags instance with only flags enabled on one of x or y, but not both. (Using
^=will update in place).
- ~x
Returns a new AttachmentFlags instance with all flags from x inverted.
- hash(x)
Returns the flag’s hash.
- iter(x)
Returns an iterator of
(name, value)pairs. This allows it to be, for example, constructed as a dict or a list of pairs. Note that aliases are not shown.
Additionally supported are a few operations on class attributes.
- AttachmentFlags.y | AttachmentFlags.z, AttachmentFlags(y=True) | AttachmentFlags.z
Returns an AttachmentFlags instance with all provided flags enabled.
- ~AttachmentFlags.y
Returns an AttachmentFlags instance with all flags except
yinverted from their default value.
New in version 2.10.
- value¶
The raw value. You should query flags via the properties rather than using this raw value.
- Type:
AllowedMentions¶
- class disnake.AllowedMentions(*, everyone=True, users=True, roles=True, replied_user=True)[source]¶
A class that represents what mentions are allowed in a message.
This class can be set during
Clientinitialisation to apply to every message sent. It can also be applied on a per message basis viaabc.Messageable.send()for more fine-grained control.- users¶
Controls the users being mentioned. If
True(the default) then users are mentioned based on the message content. IfFalsethen users are not mentioned at all. If a list ofabc.Snowflakeis given then only the users provided will be mentioned, provided those users are in the message content.- Type:
- roles¶
Controls the roles being mentioned. If
True(the default) then roles are mentioned based on the message content. IfFalsethen roles are not mentioned at all. If a list ofabc.Snowflakeis given then only the roles provided will be mentioned, provided those roles are in the message content.- Type:
- replied_user¶
Whether to mention the author of the message being replied to. Defaults to
True.New in version 1.6.
- Type:
- classmethod all()[source]¶
A factory method that returns a
AllowedMentionswith all fields explicitly set toTrueNew in version 1.5.
- classmethod none()[source]¶
A factory method that returns a
AllowedMentionswith all fields set toFalseNew in version 1.5.
- classmethod from_message(message)[source]¶
A factory method that returns a
AllowedMentionsderived from the currentMessagestate.Note that this is not what AllowedMentions the message was sent with, but what the message actually mentioned. For example, a message that successfully mentioned everyone will have
everyoneset toTrue.New in version 2.6.
MessageReference¶
- class disnake.MessageReference(*, type=MessageReferenceType.default, message_id, channel_id, guild_id=None, fail_if_not_exists=True)[source]¶
Represents a reference to a
Message.New in version 1.5.
Changed in version 1.6: This class can now be constructed by users.
- type¶
The type of the message reference.
New in version 2.10.
- Type:
- fail_if_not_exists¶
Whether replying to the referenced message should raise
HTTPExceptionif the message no longer exists or Discord could not fetch the message.New in version 1.7.
- Type:
- resolved¶
The message that this reference resolved to. If this is
Nonethen the original message was not fetched either due to the Discord API not attempting to resolve it or it not being available at the time of creation. If the message was resolved at a prior point but has since been deleted then this will be of typeDeletedReferencedMessage.Currently, this is mainly the replied to message when a user replies to a message.
New in version 1.6.
- Type:
- classmethod from_message(message, *, type=MessageReferenceType.default, fail_if_not_exists=True)[source]¶
Creates a
MessageReferencefrom an existingMessage.New in version 1.6.
- Parameters:
message (
Message) – The message to be converted into a reference.type (
MessageReferenceType) –The type of the message reference. This is used to control whether to reply to or forward a message. Defaults to replying.
New in version 2.10.
fail_if_not_exists (
bool) –Whether replying to the referenced message should raise
HTTPExceptionif the message no longer exists or Discord could not fetch the message.New in version 1.7.
- Returns:
A reference to the message.
- Return type:
PartialMessage¶
- asyncadd_reaction
- asyncclear_reaction
- asyncclear_reactions
- asyncdelete
- asyncedit
- asyncfetch
- asyncforward
- asyncpin
- asyncpublish
- asyncremove_reaction
- asyncreply
- defto_reference
- asyncunpin
- class disnake.PartialMessage(*, channel, id)[source]¶
Represents a partial message to aid with working messages when only a message and channel ID are present.
There are two ways to construct this class. The first one is through the constructor itself, and the second is via the following:
Note that this class is trimmed down and has no rich attributes.
New in version 1.6.
- x == y
Checks if two partial messages are equal.
- x != y
Checks if two partial messages are not equal.
- hash(x)
Returns the partial message’s hash.
- channel¶
The channel associated with this partial message.
- Type:
TextChannel|VoiceChannel|StageChannel|Thread|DMChannel|GroupChannel|PartialMessageable
- await delete(*, delay=None)[source]¶
This function is a coroutine.
Deletes the message.
Your own messages could be deleted without any proper permissions. However to delete other people’s messages, you need the
manage_messagespermission.Changed in version 1.1: Added the new
delaykeyword-only parameter.- Parameters:
delay (
float|None) – If provided, the number of seconds to wait in the background before deleting the message. If the deletion fails then it is silently ignored.- Raises:
Forbidden – You do not have proper permissions to delete the message.
NotFound – The message was deleted already
HTTPException – Deleting the message failed.
- await publish()[source]¶
This function is a coroutine.
Publishes this message to your announcement channel.
You must have the
send_messagespermission to do this.If the message is not your own then the
manage_messagespermission is also needed.- Raises:
Forbidden – You do not have the proper permissions to publish this message.
HTTPException – Publishing the message failed.
- await pin(*, reason=None)[source]¶
This function is a coroutine.
Pins the message.
You must have the
pin_messagespermission to do this in a non-private channel context.This does not work with messages sent in a
VoiceChannelorStageChannel.- Parameters:
The reason for pinning the message. Shows up on the audit log.
New in version 1.4.
- Raises:
Forbidden – You do not have permissions to pin the message.
NotFound – The message or channel was not found or deleted.
HTTPException – Pinning the message failed, probably due to the channel having more than 50 pinned messages or the channel not supporting pins.
- await unpin(*, reason=None)[source]¶
This function is a coroutine.
Unpins the message.
You must have the
pin_messagespermission to do this in a non-private channel context.- Parameters:
The reason for unpinning the message. Shows up on the audit log.
New in version 1.4.
- Raises:
Forbidden – You do not have permissions to unpin the message.
NotFound – The message or channel was not found or deleted.
HTTPException – Unpinning the message failed.
- await add_reaction(emoji)[source]¶
This function is a coroutine.
Adds a reaction to the message.
The emoji may be a unicode emoji or a custom guild
Emoji.You must have the
read_message_historypermission to use this. If nobody else has reacted to the message using this emoji, theadd_reactionspermission is required.Changed in version 2.6: Raises
TypeErrorinstead ofInvalidArgument.- Parameters:
emoji (
Emoji|Reaction|PartialEmoji|str) – The emoji to react with.- Raises:
HTTPException – Adding the reaction failed.
Forbidden – You do not have the proper permissions to react to the message.
NotFound – The emoji you specified was not found.
TypeError – The emoji parameter is invalid.
- await remove_reaction(emoji, member)[source]¶
This function is a coroutine.
Removes a reaction by the member from the message.
The emoji may be a unicode emoji or a custom guild
Emoji.If the reaction is not your own (i.e.
memberparameter is not you) then themanage_messagespermission is needed.The
memberparameter must represent a member and meet theabc.Snowflakeabc.Changed in version 2.6: Raises
TypeErrorinstead ofInvalidArgument.- Parameters:
emoji (
Emoji|Reaction|PartialEmoji|str) – The emoji to remove.member (
abc.Snowflake) – The member for which to remove the reaction.
- Raises:
HTTPException – Removing the reaction failed.
Forbidden – You do not have the proper permissions to remove the reaction.
NotFound – The member or emoji you specified was not found.
TypeError – The emoji parameter is invalid.
- await clear_reaction(emoji)[source]¶
This function is a coroutine.
Clears a specific reaction from the message.
The emoji may be a unicode emoji or a custom guild
Emoji.You need the
manage_messagespermission to use this.New in version 1.3.
Changed in version 2.6: Raises
TypeErrorinstead ofInvalidArgument.- Parameters:
emoji (
Emoji|Reaction|PartialEmoji|str) – The emoji to clear.- Raises:
HTTPException – Clearing the reaction failed.
Forbidden – You do not have the proper permissions to clear the reaction.
NotFound – The emoji you specified was not found.
TypeError – The emoji parameter is invalid.
- await clear_reactions()[source]¶
This function is a coroutine.
Removes all the reactions from the message.
You need the
manage_messagespermission to use this.- Raises:
HTTPException – Removing the reactions failed.
Forbidden – You do not have the proper permissions to remove all the reactions.
- await reply(content=None, *, fail_if_not_exists=True, **kwargs)[source]¶
This function is a coroutine.
A shortcut method to
abc.Messageable.send()to reply to theMessage.New in version 1.6.
Changed in version 2.3: Added
fail_if_not_existskeyword argument. Defaults toTrue.Changed in version 2.6: Raises
TypeErrororValueErrorinstead ofInvalidArgument.- Parameters:
fail_if_not_exists (
bool) –Whether replying using the message reference should raise
HTTPExceptionif the message no longer exists or Discord could not fetch the message.New in version 2.3.
- Raises:
HTTPException – Sending the message failed.
Forbidden – You do not have the proper permissions to send the message.
TypeError – You specified both
embedandembeds, orfileandfiles, orviewandcomponents.ValueError – The
filesorembedslist is too large.
- Returns:
The message that was sent.
- Return type:
- to_reference(*, type=MessageReferenceType.default, fail_if_not_exists=True)[source]¶
Creates a
MessageReferencefrom the current message.New in version 1.6.
- Parameters:
type (
MessageReferenceType) –The type of the message reference. This is used to control whether to reply to or forward a message. Defaults to replying.
New in version 2.10.
fail_if_not_exists (
bool) –Whether replying using the message reference should raise
HTTPExceptionif the message no longer exists or Discord could not fetch the message.New in version 1.7.
- Returns:
The reference to this message.
- Return type:
- await forward(channel)[source]¶
This function is a coroutine.
A shortcut method to
abc.Messageable.send()to forward aMessage.New in version 2.10.
- Parameters:
channel (
TextChannel|VoiceChannel|StageChannel|Thread|DMChannel|GroupChannel|PartialMessageable) – The channel where the message should be forwarded to.- Raises:
HTTPException – Sending the message failed.
Forbidden – You do not have the proper permissions to send the message.
- Returns:
The message that was sent.
- Return type:
- await fetch()[source]¶
This function is a coroutine.
Fetches the partial message to a full
Message.- Raises:
NotFound – The message was not found.
Forbidden – You do not have the permissions required to get a message.
HTTPException – Retrieving the message failed.
- Returns:
The full message.
- Return type:
- await edit(content=..., *, embed=..., embeds=..., file=..., files=..., attachments=..., suppress=..., suppress_embeds=..., flags=..., allowed_mentions=..., view=..., components=..., delete_after=None)[source]¶
This function is a coroutine.
Edits the message.
The content must be able to be transformed into a string via
str(content).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).Note
This method cannot be used on messages authored by others, with one exception. The
suppress_embedsparameter can be used to change the state of embeds on other users’ messages, requiring themanage_messagespermission.Changed in version 2.1:
disnake.Messageis always returned.Changed in version 2.5: The
suppresskeyword-only parameter was deprecated in favor ofsuppress_embeds.Changed in version 2.6: Raises
TypeErrorinstead ofInvalidArgument.- Parameters:
content (
str|None) – The new content to replace the message with. Could beNoneto remove the content.embed (
Embed|None) – The new embed to replace the original with. This cannot be mixed with theembedsparameter. Could beNoneto remove the embed.The new embeds to replace the original with. Must be a maximum of 10. This cannot be mixed with the
embedparameter. To remove all embeds[]should be passed.New in version 2.1.
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.1.
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.1.
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.1.
Changed in version 2.5: Supports passing
Noneto clear attachments.suppress_embeds (
bool) – Whether to suppress embeds for the message. This hides all the embeds from the UI if set toTrue. If set toFalse, this brings the embeds back if they were suppressed.flags (
MessageFlags) –The new flags to set for this message. Overrides existing flags. Only
suppress_embedsandis_components_v2are supported.If parameter
suppress_embedsis provided, that will override the setting ofMessageFlags.suppress_embeds.New in version 2.9.
delete_after (
float|None) – If provided, the number of seconds to wait in the background before deleting the message we just edited. If the deletion fails, then it is silently ignored.allowed_mentions (
AllowedMentions|None) –Controls the mentions being processed in this message. If this is passed, then the object is merged with
Client.allowed_mentions. The merging behaviour only overrides attributes that have been explicitly passed to the object, otherwise it uses the attributes set inClient.allowed_mentions.Note
Unlike
Message.edit(), this does not default toClient.allowed_mentionsif no object is passed.The updated 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]]) –The updated 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.
- Raises:
NotFound – The message was not found.
HTTPException – Editing the message failed.
Forbidden – Tried to suppress embeds on a message without permissions or edited a message’s content or embed that isn’t yours.
TypeError – You specified both
embedandembeds, orfileandfiles, orviewandcomponents.ValueError – You tried to send v2 components together with
contentorembeds.
- Returns:
The message that was edited.
- Return type:
Poll¶
- asyncexpire
- defget_answer
- class disnake.Poll(question, *, answers, duration=datetime.timedelta(days=1), allow_multiselect=False, layout_type=PollLayoutType.default)[source]¶
Represents a poll from Discord.
New in version 2.10.
- Parameters:
question (
str|PollMedia) – The question of the poll. Currently, emojis are not supported in poll questions.answers (
list[str|PollAnswer]) – The answers for this poll, up to 10.duration (
datetime.timedelta) – The total duration of the poll, up to 32 days. Defaults to 1 day. Note that this gets rounded down to the closest hour.allow_multiselect (
bool) – Whether users will be able to pick more than one answer. Defaults toFalse.layout_type (
PollLayoutType) – The layout type of the poll. Defaults toPollLayoutType.default.
- message¶
The message which contains this poll. This will be
Noneonly if this object was created manually and did not originate from the API.
- layout_type¶
The type of the layout of the poll.
- Type:
- property answers[source]¶
The list of answers for this poll.
See also
get_answer()to get specific answers by ID.- Type:
- property created_at[source]¶
When this poll was created.
Noneif this poll does not originate from the discord API.- Type:
- property expires_at[source]¶
The date when this poll will expire.
Noneif this poll does not originate from the discord API or if this poll is non-expiring.- Type:
- property remaining_duration[source]¶
The remaining duration for this poll. If this poll is finalized this property will arbitrarily return a zero valued timedelta.
Noneif this poll does not originate from the discord API.- Type:
- get_answer(answer_id, /)[source]¶
Return the requested poll answer.
- Parameters:
answer_id (
int) – The answer id.- Returns:
The requested answer.
- Return type:
- await expire()[source]¶
This function is a coroutine.
Immediately ends a poll.
Note
This method works only on Poll(s) objects that originate from the API and not on the ones built manually.
- Raises:
HTTPException – Expiring the poll failed.
Forbidden – Tried to expire a poll without the required permissions.
ValueError – You tried to invoke this method on an object that didn’t originate from the API.```
- Returns:
The message which contains the expired Poll.
- Return type:
PollAnswer¶
- defvoters
- class disnake.PollAnswer(media)[source]¶
Represents a poll answer from discord.
New in version 2.10.
- Parameters:
media (
PollMedia) – The media object to set the text and/or emoji for this answer.
- id¶
The ID of this answer. This will be
Noneonly if this object was created manually and did not originate from the API.
- poll¶
The poll associated with this answer. This will be
Noneonly if this object was created manually and did not originate from the API.
- voters(*, limit=100, after=None)[source]¶
Returns an
AsyncIteratorrepresenting the users that have voted for this answer.The
afterparameter must represent a member and meet theabc.Snowflakeabc.Note
This method works only on PollAnswer(s) objects that originate from the API and not on the ones built manually.
- Parameters:
limit (
int|None) – The maximum number of results to return. IfNone, retrieves every user who voted for this answer. Note, however, that this would make it a slow operation. Defaults to100.after (
abc.Snowflake|None) – For pagination, votes are sorted by member.
- Raises:
HTTPException – Getting the voters for this answer failed.
Forbidden – Tried to get the voters for this answer without the required permissions.
ValueError – You tried to invoke this method on an object that didn’t originate from the API.
- Yields:
User|Member– The member (if retrievable) or the user that has voted for this answer. The case where it can be aMemberis in a guild message context. Sometimes it can be aUserif the member has left the guild.
PollMedia¶
ForwardedMessage¶
- class disnake.ForwardedMessage(*, state, channel_id, guild_id, data)[source]¶
Represents a forwarded
Message.New in version 2.10.
- type¶
The type of message.
- Type:
- attachments¶
A list of attachments given to a message.
- Type:
- flags¶
Extra features of the message.
- Type:
- mentions¶
A list of
Memberthat were mentioned. If the message is in a private message then the list will be ofUserinstead. For messages that are not of typeMessageType.default, this array can be used to aid in system messages. For more information, seeMessage.system_content.Warning
The order of the mentions list is not in any particular order so you should not rely on it. This is a Discord limitation, not one with the library.
- role_mentions¶
A list of
Rolethat were mentioned. If the message is in a private message then the list is always empty.
- stickers¶
A list of sticker items given to the message.
- Type:
- property guild[source]¶
The guild where the message was forwarded from, if applicable. This could be
Noneif the guild is not cached.- Type:
- property channel[source]¶
TextChannel|VoiceChannel|StageChannel|Thread|PartialMessageable|None: The channel that the message was forwarded from. This could beNoneif the channel is not cached or adisnake.PartialMessageableif theguildis not cached or if the message forwarded is not coming from a guild (e.g DMs).
Enumerations¶
MessageType¶
- class disnake.MessageType[source]¶
Specifies the type of
Message. This is used to denote if a message is to be interpreted as a system message or a regular message.- default¶
The default message type. This is the same as regular messages.
- recipient_add¶
The system message when a user is added to a group private message or a thread.
- recipient_remove¶
The system message when a user is removed from a group private message or a thread.
- call¶
The system message denoting call state, e.g. missed call, started call, etc.
- channel_name_change¶
The system message denoting that a channel’s name has been changed.
- channel_icon_change¶
The system message denoting that a channel’s icon has been changed.
- pins_add¶
The system message denoting that a pinned message has been added to a channel.
- new_member¶
The system message denoting that a new member has joined a Guild.
The system message denoting that a member has “nitro boosted” a guild.
The system message denoting that a member has “nitro boosted” a guild and it achieved level 1.
The system message denoting that a member has “nitro boosted” a guild and it achieved level 2.
The system message denoting that a member has “nitro boosted” a guild and it achieved level 3.
- channel_follow_add¶
The system message denoting that an announcement channel has been followed.
New in version 1.3.
- guild_stream¶
The system message denoting that a member is streaming in the guild.
New in version 1.7.
- guild_discovery_disqualified¶
The system message denoting that the guild is no longer eligible for Server Discovery.
New in version 1.7.
- guild_discovery_requalified¶
The system message denoting that the guild has become eligible again for Server Discovery.
New in version 1.7.
- guild_discovery_grace_period_initial_warning¶
The system message denoting that the guild has failed to meet the Server Discovery requirements for one week.
New in version 1.7.
- guild_discovery_grace_period_final_warning¶
The system message denoting that the guild has failed to meet the Server Discovery requirements for 3 weeks in a row.
New in version 1.7.
- thread_created¶
The system message denoting that a thread has been created. This is only sent if the thread has been created from an older message. The period of time required for a message to be considered old cannot be relied upon and is up to Discord.
New in version 2.0.
- reply¶
The system message denoting that the author is replying to a message.
New in version 2.0.
- application_command¶
The system message denoting that an application (or “slash”) command was executed.
New in version 2.0.
- thread_starter_message¶
The system message denoting the message in the thread that is the one that started the thread’s conversation topic.
New in version 2.0.
- guild_invite_reminder¶
The system message sent as a reminder to invite people to the guild.
New in version 2.0.
The system message denoting that a context menu command was executed.
New in version 2.3.
- auto_moderation_action¶
The system message denoting that an auto moderation action was executed.
New in version 2.5.
- role_subscription_purchase¶
The system message denoting that a role subscription was purchased.
New in version 2.9.
The system message for an application premium subscription upsell.
New in version 2.8.
- stage_start¶
The system message denoting the stage has been started.
New in version 2.9.
- stage_end¶
The system message denoting the stage has ended.
New in version 2.9.
- stage_speaker¶
The system message denoting a user has become a speaker.
New in version 2.9.
- stage_topic¶
The system message denoting the stage topic has been changed.
New in version 2.9.
The system message denoting that a guild member has subscribed to an application.
New in version 2.8.
- guild_incident_alert_mode_enabled¶
The system message denoting that an admin enabled security actions.
New in version 2.10.
- guild_incident_alert_mode_disabled¶
The system message denoting that an admin disabled security actions.
New in version 2.10.
- guild_incident_report_raid¶
The system message denoting that an admin reported a raid.
New in version 2.10.
- guild_incident_report_false_alarm¶
The system message denoting that a raid report was a false alarm.
New in version 2.10.
- poll_result¶
The system message denoting that a poll expired, announcing the most voted answer.
New in version 2.10.
- emoji_added¶
The system message denoting that an emoji was added to the server.
PollLayoutType¶
MessageReferenceType¶
- class disnake.MessageReferenceType[source]¶
Specifies the type of
MessageReference. This can be used to determine if a message is e.g. a reply or a forwarded message.New in version 2.10.
- default¶
A standard message reference used in message replies.
- forward¶
Reference used to point to a message at a point in time (forward).