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.

name

The emoji’s name.

Type:

str

id

The emoji’s ID.

Type:

int

require_colons

Whether colons are required to use this emoji in the client (:PJSalt: vs PJSalt).

Type:

bool

animated

Whether the emoji is animated or not.

Type:

bool

managed

Whether the emoji is managed by a Twitch integration.

Type:

bool

guild_id

The guild ID the emoji belongs to.

Type:

int

available

Whether the emoji is available for use.

Type:

bool

user

The user that created this emoji. This can only be retrieved using Guild.fetch_emoji()/Guild.fetch_emojis() while having the manage_guild_expressions permission.

Type:

Optional[User]

property created_at[source]

Returns the emoji’s creation time in UTC.

Type:

datetime.datetime

property url[source]

Returns the URL of the emoji.

Type:

str

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]

property guild[source]

The guild this emoji belongs to.

Type:

Guild

is_usable()[source]

Whether the bot can use this emoji.

New in version 1.3.

Return type:

bool

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:

Emoji

await read()[source]

This function is a coroutine.

Retrieves the content of this asset as a bytes object.

Raises:
Returns:

The content of the asset.

Return type:

bytes

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:
Returns:

The number of bytes written.

Return type:

int

await to_file(*, spoiler=False, filename=None, description=None)[source]

This function is a coroutine.

Converts the asset into a File suitable for sending via abc.Messageable.send().

New in version 2.5.

Changed in version 2.6: Raises TypeError instead of InvalidArgument.

Parameters:
  • spoiler (bool) – Whether the file is a spoiler.

  • filename (Optional[str]) – The filename to display when uploading to Discord. If this is not given, it defaults to the name of the asset’s URL.

  • description (Optional[str]) – The file’s description.

Raises:
Returns:

The asset as a file suitable for sending.

Return type:

File

Data Classes

PartialEmoji

class disnake.PartialEmoji(*, name, animated=False, id=None)[source]

Represents a “partial” emoji.

This model will be given in two scenarios:

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]

animated

Whether the emoji is animated or not.

Type:

bool

id

The ID of the custom emoji, if applicable.

Type:

Optional[int]

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:

PartialEmoji

is_custom_emoji()[source]

Whether the partial emoji is a custom non-Unicode emoji.

Return type:

bool

is_unicode_emoji()[source]

Whether the partial emoji is a Unicode emoji.

Return type:

bool

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:

str

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 of InvalidArgument.

Raises:
Returns:

The content of the asset.

Return type:

bytes

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:
Returns:

The number of bytes written.

Return type:

int

await to_file(*, spoiler=False, filename=None, description=None)[source]

This function is a coroutine.

Converts the asset into a File suitable for sending via abc.Messageable.send().

New in version 2.5.

Changed in version 2.6: Raises TypeError instead of InvalidArgument.

Parameters:
  • spoiler (bool) – Whether the file is a spoiler.

  • filename (Optional[str]) – The filename to display when uploading to Discord. If this is not given, it defaults to the name of the asset’s URL.

  • description (Optional[str]) – The file’s description.

Raises:
Returns:

The asset as a file suitable for sending.

Return type:

File

Events