Messages¶
This section documents everything related to Discord messages.
Discord Models¶
Message¶
- activity
- application
- application_id
- attachments
- author
- channel
- channel_mentions
- clean_content
- components
- content
- created_at
- edited_at
- embeds
- flags
- guild
- id
- interaction
- jump_url
- mention_everyone
- mentions
- message_snapshots
- nonce
- pinned
- 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
Member
that sent the message. Ifchannel
is a private channel or the user has the left the guild, then it is aUser
instead.
- 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
DMChannel
orGroupChannel
if it’s a private message.- Type:
Union[
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 is None if the message was not sent in aThread
, or if it was sent before July 1, 2022.New in version 2.6.
- Type:
Optional[
int
]
- 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, or message replies.New in version 1.5.
- Type:
Optional[
MessageReference
]
- interaction¶
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.
- Type:
Optional[
InteractionReference
]
- mention_everyone¶
Specifies if the message mentions everyone.
Note
This does not check if the
@everyone
or the@here
text is in the message itself. Rather this boolean indicates if either the@everyone
or the@here
text is in the message and it did end up mentioning.- Type:
- mentions¶
A list of
Member
that were mentioned. If the message is in a private message then the list will be ofUser
instead. 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.
- Type:
List[
abc.User
]
- role_mentions¶
A list of
Role
that were mentioned. If the message is in a private message then the list is always empty.- Type:
List[
Role
]
- 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.
- Type:
Optional[
int
]
- webhook_id¶
If this message was sent by a webhook, then this is the webhook ID’s that sent this message.
- Type:
Optional[
int
]
- attachments¶
A list of attachments given to a message.
- Type:
List[
Attachment
]
- 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.
- Type:
List[
Reaction
]
- 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.
- Type:
Optional[
dict
]
- 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.
- Type:
Optional[
dict
]
- stickers¶
A list of sticker items given to the message.
New in version 1.6.
- Type:
List[
StickerItem
]
- message_snapshots¶
A list of forwarded messages.
New in version 2.10.
- Type:
list[
ForwardedMessage
]
- 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.
- Type:
List[
int
]
- raw_channel_mentions¶
A property that returns an array of channel IDs matched with the syntax of
<#channel_id>
in the message content.- Type:
List[
int
]
- raw_role_mentions¶
A property that returns an array of role IDs matched with the syntax of
<@&role_id>
in the message content.- Type:
List[
int
]
- channel_mentions¶
A list of
abc.GuildChannel
that were mentioned. If the message is in a private message then the list is always empty.- Type:
List[
abc.GuildChannel
]
- 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:
Optional[
datetime.datetime
]
- property thread[source]¶
The thread started from this message.
None
if no thread has been started.New in version 2.4.
- Type:
Optional[
Thread
]
- 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:
Optional[
RoleSubscriptionData
]
- 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.default
andMessageType.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
.- Type:
Optional[
str
]
- 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_messages
permission.Changed in version 1.1: Added the new
delay
keyword-only parameter.- Parameters:
delay (Optional[
float
]) – 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
file
parameter 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_embeds
parameter can be used to change the state of embeds on other users’ messages, requiring themanage_messages
permission.Changed in version 1.3: The
suppress
keyword-only parameter was added.Changed in version 2.5: The
suppress
keyword-only parameter was deprecated in favor ofsuppress_embeds
.Changed in version 2.6: Raises
TypeError
instead ofInvalidArgument
.- Parameters:
content (Optional[
str
]) – The new content to replace the message with. Could beNone
to remove the content.embed (Optional[
Embed
]) – The new embed to replace the original with. This cannot be mixed with theembeds
parameter. Could beNone
to 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 the
embed
parameter. To remove all embeds[]
should be passed.New in version 2.0.
file (
File
) –The file to upload. This cannot be mixed with the
files
parameter. Files will be appended to the message, see theattachments
parameter to remove/replace existing files.New in version 2.1.
files (List[
File
]) –A list of files to upload. This cannot be mixed with the
file
parameter. Files will be appended to the message, see theattachments
parameter to remove/replace existing files.New in version 2.1.
attachments (Optional[List[
Attachment
]]) –A list of attachments to keep in the message. If
[]
orNone
is passed then all existing attachments are removed. Keeps existing attachments if not provided.Changed in version 2.5: Supports passing
None
to 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_embeds
is supported.If parameter
suppress_embeds
is provided, that will override the setting ofMessageFlags.suppress_embeds
.New in version 2.9.
delete_after (Optional[
float
]) – 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 (Optional[
AllowedMentions
]) –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_mentions
are used instead.New in version 1.4.
view (Optional[
View
]) –The updated view to update this message with. This cannot be mixed with
components
. IfNone
is passed then the view is removed.New in version 2.0.
components (Union[
disnake.ui.ActionRow
,disnake.ui.WrappedComponent
, List[Union[disnake.ui.ActionRow
,disnake.ui.WrappedComponent
, List[disnake.ui.WrappedComponent
]]]]) –The updated components to update this message with. This cannot be mixed with
view
. IfNone
is passed then the components are removed.New in version 2.4.
- 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
embed
andembeds
, orfile
andfiles
, orview
andcomponents
.
- 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_messages
permission to do this.If the message is not your own then the
manage_messages
permission 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
manage_messages
permission to do this in a non-private channel context.This does not work with messages sent in a
VoiceChannel
orStageChannel
.- Parameters:
reason (Optional[
str
]) –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
manage_messages
permission to do this in a non-private channel context.- Parameters:
reason (Optional[
str
]) –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_history
permission to use this. If nobody else has reacted to the message using this emoji, theadd_reactions
permission is required.Changed in version 2.6: Raises
TypeError
instead ofInvalidArgument
.- Parameters:
emoji (Union[
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.
member
parameter is not you) then themanage_messages
permission is needed.The
member
parameter must represent a member and meet theabc.Snowflake
abc.Changed in version 2.6: Raises
TypeError
instead ofInvalidArgument
.- Parameters:
emoji (Union[
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_messages
permission to use this.New in version 1.3.
Changed in version 2.6: Raises
TypeError
instead ofInvalidArgument
.- Parameters:
emoji (Union[
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_messages
permission 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_threads
in 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
TypeError
instead ofInvalidArgument
.- Parameters:
name (
str
) – The name of the thread.auto_archive_duration (Union[
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
.slowmode_delay (Optional[
int
]) –Specifies the slowmode rate limit for users in this thread, in seconds. A value of
0
disables slowmode. The maximum value possible is21600
. If set toNone
or not provided, slowmode is inherited from the parent’sdefault_thread_slowmode_delay
.New in version 2.3.
reason (Optional[
str
]) –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_exists
keyword argument. Defaults toTrue
.Changed in version 2.6: Raises
TypeError
orValueError
instead ofInvalidArgument
.- Parameters:
fail_if_not_exists (
bool
) –Whether replying using the message reference should raise
HTTPException
if 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
embed
andembeds
, orfile
andfiles
, orview
andcomponents
.ValueError – The
files
orembeds
list 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 (Union[
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: 0>, fail_if_not_exists=True)[source]¶
Creates a
MessageReference
from 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
HTTPException
if 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:
Union[
Emoji
,PartialEmoji
,str
]
- async for ... in users(*, limit=None, after=None)[source]¶
Returns an
AsyncIterator
representing the users that have reacted to the message.The
after
parameter must represent a member and meet theabc.Snowflake
abc.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 (Optional[
int
]) – The maximum number of results to return. If not provided, returns all the users who reacted to the message.after (Optional[
abc.Snowflake
]) – For pagination, reactions are sorted by member.
- Raises:
HTTPException – Getting the users for the reaction failed.
- Yields:
Union[
User
,Member
] – The member (if retrievable) or the user that has reacted to this message. The case where it can be aMember
is in a guild message context. Sometimes it can be aUser
if the member has left the guild.
- await remove(user)[source]¶
This function is a coroutine.
Removes the reaction by the provided
User
from the message.If the reaction is not your own (i.e.
user
parameter is not you) then themanage_messages
permission is needed.The
user
parameter must represent a user or member and meet theabc.Snowflake
abc.- 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_messages
permission to use this.New in version 1.3.
Changed in version 2.6: Raises
TypeError
instead 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
str
and is hashable.- height¶
The attachment’s height, in pixels. Only applicable to images and videos.
- Type:
Optional[
int
]
- 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.
- Type:
Optional[
str
]
- 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
url
in 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.
- Type:
Optional[
str
]
- 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.
- Type:
Optional[
float
]
- 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.
- Type:
Optional[
bytes
]
- 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 (Union[
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_url
rather thanurl
when 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
bytes
object.New in version 1.1.
- Parameters:
use_cached (
bool
) – Whether to useproxy_url
rather thanurl
when 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
File
suitable for sending viaabc.Messageable.send()
.New in version 1.3.
- Parameters:
use_cached (
bool
) –Whether to use
proxy_url
rather thanurl
when 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.
description (Optional[
str
]) –The file’s description. Copies this attachment’s description by default, set to
None
to 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(*, state, guild, data)[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.
- 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:
RoleSubscriptionData¶
- class disnake.RoleSubscriptionData(data)[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:
RawTypingEvent¶
- class disnake.RawTypingEvent[source]¶
Represents the event payload for an
on_raw_typing()
event.New in version 2.3.
- guild_id¶
The ID of the guild where the user started typing or
None
if it was in a DM.- Type:
Optional[
int
]
- member¶
The member object of the user who started typing or
None
if it was in a DM.- Type:
Optional[
Member
]
- 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.
- Type:
Optional[
int
]
- 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
.- Type:
Optional[
Message
]
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.
- Type:
Optional[
Member
]
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.
- Type:
Optional[
int
]
- emoji¶
The custom or unicode emoji being used.
Changed in version 2.9: This now also includes the correct
animated
value when a reaction was removed.- Type:
- member¶
The member who added the reaction. Only available if
event_type
isREACTION_ADD
and the reaction is inside a guild.New in version 1.3.
- Type:
Optional[
Member
]
- event_type¶
The event type that triggered this action. Can be
REACTION_ADD
for reaction addition orREACTION_REMOVE
for 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_type
isREACTION_ADD
. May also beNone
if the message was created by a webhook.New in version 2.10.
- Type:
Optional[
int
]
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 regulardict
except using dotted access, e.g.embed.author.icon_url
.For ease of use, all parameters that expect a
str
are implicitly cast tostr
for you.- type¶
The type of embed. Usually “rich”. Possible strings for embed types can be found on Discord’s api-docs.
- Type:
Optional[
str
]
- 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:
Optional[
datetime.datetime
]
- colour[source]¶
The colour code of the embed. Aliased to
color
as well. In addition toColour
,int
can also be assigned to it, in which case the value will be converted to aColour
object.- Type:
Optional[
Colour
]
- classmethod from_dict(data)[source]¶
Converts a
dict
to aEmbed
provided 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
EmbedProxy
denoting the footer contents.Possible attributes you can access are:
text
icon_url
proxy_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_url
oricon_file
may be passed.Warning
Passing a
disnake.File
object will make the embed not reusable.Warning
If used with the other
set_*
methods, you must ensure that theFile.filename
is 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
EmbedProxy
denoting the image contents.Possible attributes you can access are:
url
proxy_url
width
height
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
url
orfile
must be passed.Warning
Passing a
disnake.File
object will make the embed not reusable.Warning
If used with the other
set_*
methods, you must ensure that theFile.filename
is unique to avoid duplication.Changed in version 1.4: Passing
None
removes the image.
- property thumbnail[source]¶
Returns an
EmbedProxy
denoting the thumbnail contents.Possible attributes you can access are:
url
proxy_url
width
height
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
url
orfile
must be passed.Warning
Passing a
disnake.File
object will make the embed not reusable.Warning
If used with the other
set_*
methods, you must ensure that theFile.filename
is unique to avoid duplication.Changed in version 1.4: Passing
None
removes the thumbnail.
- property video[source]¶
Returns an
EmbedProxy
denoting the video contents.Possible attributes include:
url
for the video URL.proxy_url
for the proxied video URL.height
for the video height.width
for the video width.
If an attribute is not set, it will be
None
.
- property provider[source]¶
Returns an
EmbedProxy
denoting the provider contents.The only attributes that might be accessed are
name
andurl
.If an attribute is not set, it will be
None
.
- property author[source]¶
Returns an
EmbedProxy
denoting 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_url
oricon_file
may be passed.Warning
Passing a
disnake.File
object will make the embed not reusable.Warning
If used with the other
set_*
methods, you must ensure that theFile.filename
is 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
list
ofEmbedProxy
denoting 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.
- Returns:
The colour that was set.
- Return type:
Optional[
Colour
]
- classmethod set_default_color(value)[source]¶
Set the default colour of all new embeds.
New in version 2.4.
- Returns:
The colour that was set.
- Return type:
Optional[
Colour
]
- classmethod get_default_colour()[source]¶
Get the default colour of all new embeds.
New in version 2.4.
- Returns:
The default colour.
- Return type:
Optional[
Colour
]
- classmethod get_default_color()[source]¶
Get the default colour of all new embeds.
New in version 2.4.
- Returns:
The default colour.
- Return type:
Optional[
Colour
]
- 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
ValueError
if 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
open
then the modes ‘rb’ should be used.To pass binary data, consider usage of
io.BytesIO
.- Type:
Union[
os.PathLike
,io.BufferedIOBase
]
- filename¶
The filename to display when uploading to Discord. If this is not given then it defaults to
fp.name
or iffp
is a string then thefilename
will default to the string given.- Type:
Optional[
str
]
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
y
inverted 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
True
if the source message for this crosspost has been deleted.- Type:
- urgent¶
Returns
True
if the message is an urgent message.An urgent message is one sent by Discord Trust and Safety.
- Type:
- loading¶
Returns
True
if 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
True
if the message failed to mention some roles and add their members to the thread.New in version 2.4.
- Type:
- suppress_notifications¶
Returns
True
if the message does not trigger push and desktop notifications.New in version 2.9.
- Type:
- is_voice_message¶
Returns
True
if 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:
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 a AttachmentFlags instance with all provided flags enabled.
- ~AttachmentFlags.y
Returns a AttachmentFlags instance with all flags except
y
inverted 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
Client
initialisation 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. IfFalse
then users are not mentioned at all. If a list ofabc.Snowflake
is given then only the users provided will be mentioned, provided those users are in the message content.- Type:
Union[
bool
, List[abc.Snowflake
]]
- roles¶
Controls the roles being mentioned. If
True
(the default) then roles are mentioned based on the message content. IfFalse
then roles are not mentioned at all. If a list ofabc.Snowflake
is given then only the roles provided will be mentioned, provided those roles are in the message content.- Type:
Union[
bool
, List[abc.Snowflake
]]
- 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
AllowedMentions
with all fields explicitly set toTrue
New in version 1.5.
- classmethod none()[source]¶
A factory method that returns a
AllowedMentions
with all fields set toFalse
New in version 1.5.
- classmethod from_message(message)[source]¶
A factory method that returns a
AllowedMentions
derived from the currentMessage
state.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
everyone
set toTrue
.New in version 2.6.
MessageReference¶
- class disnake.MessageReference(*, type=<MessageReferenceType.default: 0>, 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
HTTPException
if 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
None
then 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:
Optional[Union[
Message
,DeletedReferencedMessage
]]
- classmethod from_message(message, *, type=<MessageReferenceType.default: 0>, fail_if_not_exists=True)[source]¶
Creates a
MessageReference
from 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
HTTPException
if 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:
Union[
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_messages
permission.Changed in version 1.1: Added the new
delay
keyword-only parameter.- Parameters:
delay (Optional[
float
]) – 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_messages
permission to do this.If the message is not your own then the
manage_messages
permission 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
manage_messages
permission to do this in a non-private channel context.This does not work with messages sent in a
VoiceChannel
orStageChannel
.- Parameters:
reason (Optional[
str
]) –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
manage_messages
permission to do this in a non-private channel context.- Parameters:
reason (Optional[
str
]) –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_history
permission to use this. If nobody else has reacted to the message using this emoji, theadd_reactions
permission is required.Changed in version 2.6: Raises
TypeError
instead ofInvalidArgument
.- Parameters:
emoji (Union[
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.
member
parameter is not you) then themanage_messages
permission is needed.The
member
parameter must represent a member and meet theabc.Snowflake
abc.Changed in version 2.6: Raises
TypeError
instead ofInvalidArgument
.- Parameters:
emoji (Union[
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_messages
permission to use this.New in version 1.3.
Changed in version 2.6: Raises
TypeError
instead ofInvalidArgument
.- Parameters:
emoji (Union[
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_messages
permission 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_exists
keyword argument. Defaults toTrue
.Changed in version 2.6: Raises
TypeError
orValueError
instead ofInvalidArgument
.- Parameters:
fail_if_not_exists (
bool
) –Whether replying using the message reference should raise
HTTPException
if 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
embed
andembeds
, orfile
andfiles
, orview
andcomponents
.ValueError – The
files
orembeds
list is too large.
- Returns:
The message that was sent.
- Return type:
- to_reference(*, type=<MessageReferenceType.default: 0>, fail_if_not_exists=True)[source]¶
Creates a
MessageReference
from 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
HTTPException
if 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 (Union[
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
file
parameter 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_embeds
parameter can be used to change the state of embeds on other users’ messages, requiring themanage_messages
permission.Changed in version 2.1:
disnake.Message
is always returned.Changed in version 2.5: The
suppress
keyword-only parameter was deprecated in favor ofsuppress_embeds
.Changed in version 2.6: Raises
TypeError
instead ofInvalidArgument
.- Parameters:
content (Optional[
str
]) – The new content to replace the message with. Could beNone
to remove the content.embed (Optional[
Embed
]) – The new embed to replace the original with. This cannot be mixed with theembeds
parameter. Could beNone
to 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 the
embed
parameter. To remove all embeds[]
should be passed.New in version 2.1.
file (
File
) –The file to upload. This cannot be mixed with the
files
parameter. Files will be appended to the message, see theattachments
parameter to remove/replace existing files.New in version 2.1.
files (List[
File
]) –A list of files to upload. This cannot be mixed with the
file
parameter. Files will be appended to the message, see theattachments
parameter to remove/replace existing files.New in version 2.1.
attachments (Optional[List[
Attachment
]]) –A list of attachments to keep in the message. If
[]
orNone
is 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
None
to 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_embeds
is supported.If parameter
suppress_embeds
is provided, that will override the setting ofMessageFlags.suppress_embeds
.New in version 2.9.
delete_after (Optional[
float
]) – 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 (Optional[
AllowedMentions
]) –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_mentions
if no object is passed.view (Optional[
View
]) –The updated view to update this message with. This cannot be mixed with
components
. IfNone
is passed then the view is removed.New in version 2.0.
components (Union[
disnake.ui.ActionRow
,disnake.ui.WrappedComponent
, List[Union[disnake.ui.ActionRow
,disnake.ui.WrappedComponent
, List[disnake.ui.WrappedComponent
]]]]) –The updated components to update this message with. This cannot be mixed with
view
. IfNone
is passed then the components are removed.New in version 2.4.
- 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
embed
andembeds
, orfile
andfiles
, orview
andcomponents
.
- 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: 1>)[source]¶
Represents a poll from Discord.
New in version 2.10.
- Parameters:
question (Union[
str
,PollMedia
]) – The question of the poll. Currently, emojis are not supported in poll questions.answers (List[Union[
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
None
only if this object was created manually and did not originate from the API.- Type:
Optional[
Message
]
- duration¶
The original duration for this poll.
None
if the poll is a non-expiring poll.- Type:
Optional[
datetime.timedelta
]
- 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:
List[
PollAnswer
]
- property created_at[source]¶
When this poll was created.
None
if this poll does not originate from the discord API.- Type:
Optional[
datetime.datetime
]
- property expires_at[source]¶
The date when this poll will expire.
None
if this poll does not originate from the discord API or if this poll is non-expiring.- Type:
Optional[
datetime.datetime
]
- property remaining_duration[source]¶
The remaining duration for this poll. If this poll is finalized this property will arbitrarily return a zero valued timedelta.
None
if this poll does not originate from the discord API.- Type:
Optional[
datetime.timedelta
]
- get_answer(answer_id, /)[source]¶
Return the requested poll answer.
- Parameters:
answer_id (
int
) – The answer id.- Returns:
The requested answer.
- Return type:
Optional[
PollAnswer
]
- 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
None
only if this object was created manually and did not originate from the API.- Type:
Optional[
int
]
- poll¶
The poll associated with this answer. This will be
None
only if this object was created manually and did not originate from the API.- Type:
Optional[
Poll
]
- voters(*, limit=100, after=None)[source]¶
Returns an
AsyncIterator
representing the users that have voted for this answer.The
after
parameter must represent a member and meet theabc.Snowflake
abc.Note
This method works only on PollAnswer(s) objects that originate from the API and not on the ones built manually.
- Parameters:
limit (Optional[
int
]) – 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 (Optional[
abc.Snowflake
]) – 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:
Union[
User
,Member
] – The member (if retrievable) or the user that has voted for this answer. The case where it can be aMember
is in a guild message context. Sometimes it can be aUser
if the member has left the guild.
PollMedia¶
- class disnake.PollMedia(text, *, emoji=None)[source]¶
Represents data of a poll’s question/answers.
New in version 2.10.
- Parameters:
text (
str
) – The text of this media.emoji (Optional[Union[
Emoji
,PartialEmoji
,str
]]) – The emoji of this media.
- emoji¶
The emoji of this media.
- Type:
Optional[
PartialEmoji
]
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:
List[
Attachment
]
- flags¶
Extra features of the message.
- Type:
- mentions¶
A list of
Member
that were mentioned. If the message is in a private message then the list will be ofUser
instead. 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.
- Type:
List[
abc.User
]
- role_mentions¶
A list of
Role
that were mentioned. If the message is in a private message then the list is always empty.- Type:
List[
Role
]
- stickers¶
A list of sticker items given to the message.
- Type:
List[
StickerItem
]
- property guild[source]¶
The guild where the message was forwarded from, if applicable. This could be
None
if the guild is not cached.- Type:
Optional[
disnake.Guild
]
- property channel[source]¶
Optional[Union[
TextChannel
,VoiceChannel
,StageChannel
,Thread
,PartialMessageable
]]: The channel that the message was forwarded from. This could beNone
if the channel is not cached or adisnake.PartialMessageable
if theguild
is not cached or if the message forwarded is not coming from a guild (e.g DMs).
- property edited_at[source]¶
An aware UTC datetime object containing the edited time of the message.
- Type:
Optional[
datetime.datetime
]
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.- x == y
Checks if two messages are equal.
- x != y
Checks if two messages are not equal.
- 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.
- guild_invite_reminder¶
The system message sent as a reminder to invite people to the guild.
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.
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.
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).