Emoji¶
This section documents everything related to Discord emoji.
Discord Models¶
Emoji¶
- class disnake.Emoji[source]¶
Represents a custom emoji.
Depending on the way this object was created, some of the attributes can have a value of
None
.- x == y
Checks if two emoji are the same.
- x != y
Checks if two emoji are not the same.
- hash(x)
Return the emoji’s hash.
- iter(x)
Returns an iterator of
(field, value)
pairs. This allows this class to be used as an iterable in list/dict/etc constructions.
- str(x)
Returns the emoji rendered for Discord.
- require_colons¶
Whether colons are required to use this emoji in the client (:PJSalt: vs PJSalt).
- Type:
- user¶
The user that created this emoji. This can only be retrieved using
Guild.fetch_emoji()
/Guild.fetch_emojis()
while having themanage_guild_expressions
permission.- Type:
Optional[
User
]
- property roles[source]¶
A
list
of roles that are allowed to use this emoji.If roles is empty, the emoji is unrestricted.
Emojis with
subscription roles
are considered premium emojis, and count towards a separate limit of 25 emojis.- Type:
List[
Role
]
- await delete(*, reason=None)[source]¶
This function is a coroutine.
Deletes the custom emoji.
You must have
manage_guild_expressions
permission to do this.- Parameters:
reason (Optional[
str
]) – The reason for deleting this emoji. Shows up on the audit log.- Raises:
Forbidden – You are not allowed to delete this emoji.
HTTPException – An error occurred deleting the emoji.
- await edit(*, name=..., roles=..., reason=None)[source]¶
This function is a coroutine.
Edits the custom emoji.
You must have
manage_guild_expressions
permission to do this.Changed in version 2.0: The newly updated emoji is returned.
- Parameters:
name (
str
) – The new emoji name.roles (Optional[List[
Snowflake
]]) –A list of roles that can use this emoji. An empty list can be passed to make it available to everyone.
An emoji cannot have both subscription roles (see
RoleTags.integration_id
) and non-subscription roles, and emojis can’t be converted between premium and non-premium after creation.reason (Optional[
str
]) – The reason for editing this emoji. Shows up on the audit log.
- Raises:
Forbidden – You are not allowed to edit this emoji.
HTTPException – An error occurred editing the emoji.
- Returns:
The newly updated emoji.
- Return type:
- await read()[source]¶
This function is a coroutine.
Retrieves the content of this asset as a
bytes
object.- Raises:
DiscordException – There was no internal connection state.
HTTPException – Downloading the asset failed.
NotFound – The asset was deleted.
- Returns:
The content of the asset.
- Return type:
- await save(fp, *, seek_begin=True)[source]¶
This function is a coroutine.
Saves this asset into a file-like object.
- Parameters:
fp (Union[
io.BufferedIOBase
,os.PathLike
]) – The file-like object to save this asset 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.
- Raises:
DiscordException – There was no internal connection state.
HTTPException – Downloading the asset failed.
NotFound – The asset was deleted.
- Returns:
The number of bytes written.
- Return type:
- await to_file(*, spoiler=False, filename=None, description=None)[source]¶
This function is a coroutine.
Converts the asset into a
File
suitable for sending viaabc.Messageable.send()
.New in version 2.5.
Changed in version 2.6: Raises
TypeError
instead ofInvalidArgument
.- Parameters:
- Raises:
DiscordException – The asset does not have an associated state.
HTTPException – Downloading the asset failed.
NotFound – The asset was deleted.
TypeError – The asset is a unicode emoji or a sticker with lottie type.
- Returns:
The asset as a file suitable for sending.
- Return type:
Data Classes¶
PartialEmoji¶
- clsPartialEmoji.from_str
- defis_custom_emoji
- defis_unicode_emoji
- asyncread
- asyncsave
- asyncto_file
- class disnake.PartialEmoji(*, name, animated=False, id=None)[source]¶
Represents a “partial” emoji.
This model will be given in two scenarios:
“Raw” data events such as
on_raw_reaction_add()
Custom emoji that the bot cannot see from e.g.
Message.reactions
- x == y
Checks if two emoji are the same.
- x != y
Checks if two emoji are not the same.
- hash(x)
Return the emoji’s hash.
- str(x)
Returns the emoji rendered for Discord.
- name¶
The custom emoji name, if applicable, or the unicode codepoint of the non-custom emoji. This can be
None
if the emoji got deleted (e.g. removing a reaction with a deleted emoji).- Type:
Optional[
str
]
- classmethod from_str(value)[source]¶
Converts a Discord string representation of an emoji to a
PartialEmoji
.The formats accepted are:
a:name:id
<a:name:id>
name:id
<:name:id>
If the format does not match then it is assumed to be a unicode emoji.
New in version 2.0.
- Parameters:
value (
str
) – The string representation of an emoji.- Returns:
The partial emoji from this string.
- Return type:
- property created_at[source]¶
Returns the emoji’s creation time in UTC, or None if it’s a Unicode emoji.
New in version 1.6.
- Type:
Optional[
datetime.datetime
]
- property url[source]¶
Returns the URL of the emoji, if it is custom.
If this isn’t a custom emoji then an empty string is returned
- Type:
- await read()[source]¶
This function is a coroutine.
Retrieves the data of this emoji as a
bytes
object.Changed in version 2.6: Raises
TypeError
instead ofInvalidArgument
.- Raises:
TypeError – The emoji is not a custom emoji.
DiscordException – There was no internal connection state.
HTTPException – Downloading the asset failed.
NotFound – The asset was deleted.
- Returns:
The content of the asset.
- Return type:
- await save(fp, *, seek_begin=True)[source]¶
This function is a coroutine.
Saves this asset into a file-like object.
- Parameters:
fp (Union[
io.BufferedIOBase
,os.PathLike
]) – The file-like object to save this asset 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.
- Raises:
DiscordException – There was no internal connection state.
HTTPException – Downloading the asset failed.
NotFound – The asset was deleted.
- Returns:
The number of bytes written.
- Return type:
- await to_file(*, spoiler=False, filename=None, description=None)[source]¶
This function is a coroutine.
Converts the asset into a
File
suitable for sending viaabc.Messageable.send()
.New in version 2.5.
Changed in version 2.6: Raises
TypeError
instead ofInvalidArgument
.- Parameters:
- Raises:
DiscordException – The asset does not have an associated state.
HTTPException – Downloading the asset failed.
NotFound – The asset was deleted.
TypeError – The asset is a unicode emoji or a sticker with lottie type.
- Returns:
The asset as a file suitable for sending.
- Return type: