hikari.emojis#

Application and entities that are used to describe emojis on Discord.

Module Contents#

class hikari.emojis.Emoji[source]#

Bases: hikari.files.WebResource, abc.ABC

Base class for all emojis.

Any emoji implementation supports being used as a hikari.files.Resource when uploading an attachment to the API. This is achieved in the same way as using a hikari.files.WebResource would achieve this.

abstract property name: str[source]#

Return the generic name/representation for this emoji.

abstract property url: str[source]#

URL of the emoji image to display in clients.

abstract property url_name: str[source]#

Name of the part of the emoji to use in requests.

abstract property mention: str[source]#

Mention string to use to mention the emoji with.

classmethod parse(string, /)[source]#

Parse a given string into an emoji object.

Parameters
stringstr

The emoji object to parse.

Returns
Emoji

The parsed emoji object. This will be a CustomEmoji if a custom emoji mention, or a UnicodeEmoji otherwise.

Raises
ValueError

If a mention is given that has an invalid format.

class hikari.emojis.UnicodeEmoji[source]#

Bases: str, Emoji

Represents a unicode emoji.

Warning

A word of warning if you try to upload this emoji as a file attachment.

While this emoji type can be used to upload the Twemoji representations of this emoji as a PNG, this is NOT foolproof. The mapping between Discord’s implementation and official Twemoji bindings is very flaky. Responsible implementations relying on this behaviour will be implemented to expect this behaviour in the form of hikari.errors.NotFoundError exceptions being raised when a mismatch may occur. It is also likely that this will change in the future without notice, so you will likely be relying on flaky behaviour.

If this is proven to be too unstable, this functionality will be removed in a future release after a deprecation period.

property name: str[source]#

Return the code points which form the emoji.

property url_name: str[source]#

Name of the part of the emoji to use in requests.

property mention: str[source]#

Mention string to use to mention the emoji with.

property codepoints: Sequence[int][source]#

Integer codepoints that make up this emoji, as UTF-8.

property filename: str[source]#

Filename to use if re-uploading this emoji’s PNG.

property url: str[source]#

Get the URL of the PNG rendition of this emoji.

This will use the official Twitter “twemoji” repository to fetch this information, as Discord only stores this in a hashed format that uses SVG files, which is not usually of any use.

Since this uses “twemoji” directly, the emojis may not directly match what is on Discord if Discord have failed to keep their emoji packs up-to-date with this repository.

Examples

>>> emoji = hikari.UnicodeEmoji("👌")
>>> emoji.url
'https://raw.githubusercontent.com/twitter/twemoji/master/assets/72x72/1f44c.png'
property unicode_escape: str[source]#

Get the unicode escape string for this emoji.

classmethod parse_codepoints(codepoint, *codepoints)[source]#

Create a unicode emoji from one or more UTF-32 codepoints.

classmethod parse_unicode_escape(escape)[source]#

Create a unicode emoji from a unicode escape string.

classmethod parse(string, /)[source]#

Parse a given string into a unicode emoji object.

Parameters
stringstr

The emoji object to parse.

Returns
UnicodeEmoji

The parsed UnicodeEmoji object.

class hikari.emojis.CustomEmoji[source]#

Bases: hikari.snowflakes.Unique, Emoji

Represents a custom emoji.

This is a custom emoji that is from a guild you might not be part of.

All CustomEmoji objects and their derivatives act as valid hikari.files.Resource objects. This means you can use them as a file when sending a message.

>>> emojis = await bot.rest.fetch_guild_emojis(12345)
>>> picks = random.choices(emojis, 5)
>>> await event.respond(files=picks)

Warning

Discord will not provide information on whether these emojis are animated or not when a reaction is removed and an event is fired. This is problematic if you need to try and determine the emoji that was removed. The side effect of this means that mentions for animated emojis will not be correct.

This will not be changed as stated here: <https://github.com/discord/discord-api-docs/issues/1614#issuecomment-628548913>

id: hikari.snowflakes.Snowflake[source]#

The ID of this entity.

name: str[source]#

The name of the emoji.

is_animated: bool[source]#

Whether the emoji is animated.

classmethod parse(string, /)[source]#

Parse a given emoji mention string into a custom emoji object.

Parameters
stringstr

The emoji mention to parse.

Returns
CustomEmoji

The parsed emoji object.

Raises
ValueError

If a mention is given that has an invalid format.

class hikari.emojis.KnownCustomEmoji[source]#

Bases: CustomEmoji

Represents an emoji that is known from a guild the bot is in.

This is a specialization of CustomEmoji that is from a guild that you _are_ part of. As a result, it contains a lot more information with it.

app: hikari.traits.RESTAware[source]#

Client application that models may use for procedures.

guild_id: hikari.snowflakes.Snowflake[source]#

The ID of the guild this emoji belongs to.

role_ids: Sequence[hikari.snowflakes.Snowflake][source]#

The IDs of the roles that are whitelisted to use this emoji.

If this is empty then any user can use this emoji regardless of their roles.

user: Optional[hikari.users.User][source]#

The user that created the emoji.

Note

This will be None if you are missing the MANAGE_EMOJIS_AND_STICKERS permission in the server the emoji is from.

is_colons_required: bool[source]#

Whether this emoji must be wrapped in colons.

is_managed: bool[source]#

Whether the emoji is managed by an integration.

is_available: bool[source]#

Whether this emoji can currently be used.

May be False due to a loss of Sever Boosts on the emoji’s guild.