hikari.snowflakes#

Implementation of a Snowflake type.

Module Contents#

class hikari.snowflakes.Snowflake[source]#

Bases: int

A concrete representation of a unique ID for an entity on Discord.

This object can be treated as a regular int for most purposes.

property created_at: datetime.datetime[source]#

When the object was created.

property internal_worker_id: int[source]#

ID of the worker that created this snowflake on Discord’s systems.

property internal_process_id: int[source]#

ID of the process that created this snowflake on Discord’s systems.

property increment: int[source]#

Increment of Discord’s system when this object was made.

classmethod from_datetime(timestamp)[source]#

Get a snowflake object from a datetime object.

classmethod min()[source]#

Minimum value for a snowflakes.

classmethod max()[source]#

Maximum value for a snowflakes.

classmethod from_data(timestamp, worker_id, process_id, increment)[source]#

Convert the pieces of info that comprise an ID into a Snowflake.

class hikari.snowflakes.Unique[source]#

Bases: abc.ABC

Mixin for a class that enforces uniqueness by a snowflake ID.

abstract property id: Snowflake[source]#

ID of this entity.

property created_at: datetime.datetime[source]#

When the object was created.

hikari.snowflakes.calculate_shard_id(app_or_count, guild)[source]#

Calculate the shard ID for a guild based on it’s shard aware app or shard count.

Parameters
app_or_counttyping.Union[hikari.traits.ShardAware, int]

The shard aware app of the current application or the integer count of the current app’s shards.

guildSnowflakeishOr[hikari.guilds.PartialGuild]

The object or ID of the guild to get the shard ID of.

Returns
int

The zero-indexed integer ID of the shard that should cover this guild.

hikari.snowflakes.Snowflakeish[source]#

Type hint for a value that resembles a Snowflake object functionally.

This is a value that is Snowflake-ish.

A value is Snowflake-ish if casting it to an int allows it to be cast to a Snowflake.

The valid types for this type hint are:

hikari.snowflakes.SearchableSnowflakeish[source]#

Type hint for a snowflakeish that can be searched for in history.

This is just a Snowflakeish that can alternatively be some form of datetime.datetime instance.

The valid types for this type hint are:

hikari.snowflakes.SnowflakeishOr[source]#

Type hint representing a unique object entity.

This is a value that is Snowflake-ish or a specific type covariant.

If you see SnowflakeishOr[Foo] anywhere as a type hint, it means the value may be a Foo instance, a Snowflake, a int or a str with numeric digits only.

Essentially this represents any concrete object, or ID of that object. It is used across Hikari’s API to allow use of functions when information is only partially available (due to Discord inconsistencies, edge case behaviour, or use of intents).

The valid types for this type hint are:

hikari.snowflakes.SearchableSnowflakeishOr[source]#

Type hint for a unique object entity that can be searched for.

This is a variant of SnowflakeishOr that also allows an alternative value of a datetime.datetime to be specified.

Essentially this represents any concrete object, or ID of that object. It is used across Hikari’s API to allow use of functions when information is only partially available (due to Discord inconsistencies, edge case behaviour, or use of intents).

The valid types for this type hint are:

hikari.snowflakes.SnowflakeishIterable[source]#

Type hint representing an iterable of unique object entities.

hikari.snowflakes.SnowflakeishSequence[source]#

Type hint representing a collection of unique object entities.