Skip to content

hikari.snowflakes#

Implementation of a Snowflake type.

SearchableSnowflakeish module-attribute #

SearchableSnowflakeish = Union[Snowflakeish, 'datetime.datetime']

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

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

The valid types for this type hint are:

SearchableSnowflakeishOr module-attribute #

SearchableSnowflakeishOr = Union[T, SearchableSnowflakeish]

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

This is a variant of hikari.snowflakes.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:

Snowflakeish module-attribute #

Snowflakeish = Union[Snowflake, int]

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

This is a value that is hikari.snowflakes.Snowflake-ish.

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

The valid types for this type hint are:

SnowflakeishIterable module-attribute #

SnowflakeishIterable = Iterable[SnowflakeishOr[T]]

Type hint representing an iterable of unique object entities.

SnowflakeishOr module-attribute #

SnowflakeishOr = Union[T, Snowflakeish]

Type hint representing a unique object entity.

This is a value that is hikari.snowflakes.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 hikari.snowflakes.Snowflake, an 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:

SnowflakeishSequence module-attribute #

SnowflakeishSequence = Sequence[SnowflakeishOr[T]]

Type hint representing a collection of unique object entities.

Snowflake #

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.

created_at property #

created_at: datetime

When the object was created.

increment property #

increment: int

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

internal_process_id property #

internal_process_id: int

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

internal_worker_id property #

internal_worker_id: int

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

from_data classmethod #

from_data(
    timestamp: datetime, worker_id: int, process_id: int, increment: int
) -> Snowflake

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

from_datetime classmethod #

from_datetime(timestamp: datetime) -> Snowflake

Get a snowflake object from a datetime object.

max classmethod #

max() -> Snowflake

Maximum value for a snowflakes.

min classmethod #

min() -> Snowflake

Minimum value for a snowflakes.

Unique #

Bases: ABC

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

created_at property #

created_at: datetime

When the object was created.

id abstractmethod property #

ID of this entity.

calculate_shard_id #

calculate_shard_id(
    app_or_count: Union[ShardAware, int], guild: SnowflakeishOr[PartialGuild]
) -> int

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

PARAMETER DESCRIPTION
app_or_count

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

TYPE: Union[ShardAware, int]

guild

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

TYPE: SnowflakeishOr[PartialGuild]

RETURNS DESCRIPTION
int

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