Skip to content

hikari.impl.shard#

Single-shard implementation for the V10 event gateway for Discord.

GatewayShardImpl #

GatewayShardImpl(*, compression: Optional[str] = shard.GatewayCompression.TRANSPORT_ZLIB_STREAM, dumps: JSONEncoder = data_binding.default_json_dumps, loads: JSONDecoder = data_binding.default_json_loads, initial_activity: Optional[Activity] = None, initial_idle_since: Optional[datetime] = None, initial_is_afk: bool = False, initial_status: Status = presences.Status.ONLINE, intents: Intents, large_threshold: int = 250, shard_id: int = 0, shard_count: int = 1, http_settings: HTTPSettings, proxy_settings: ProxySettings, data_format: str = shard.GatewayDataFormat.JSON, event_manager: EventManager, event_factory: EventFactory, token: str, url: str)

Bases: GatewayShard

Implementation of a V10 compatible gateway.

Note

If all four of initial_activity, initial_idle_since, initial_is_afk, and initial_status are not defined and left to their default values, then the presence will not be updated on startup at all. If any of these are specified, then any that are not specified will be set to sane defaults, which may change the previous status. This will only occur during startup, and is an artifact of how Discord manages these updates internally. All other calls to update the status of the shard will support partial updates.

PARAMETER DESCRIPTION
token

The bot token to use.

TYPE: str

url

The gateway URL to use. This should not contain a query-string or fragments.

TYPE: str

event_manager

The event manager this shard should make calls to.

TYPE: EventManager

event_factory

The event factory this shard should use.

TYPE: EventFactory

compression

Compression format to use for the shard. Only supported values are "transport_zlib_stream" or None to disable it.

TYPE: Optional[str] DEFAULT: TRANSPORT_ZLIB_STREAM

dumps

The JSON encoder this application should use.

TYPE: JSONEncoder DEFAULT: default_json_dumps

loads

The JSON decoder this application should use.

TYPE: JSONDecoder DEFAULT: default_json_loads

initial_activity

The initial activity to appear to have for this shard, or None if no activity should be set initially. This is the default.

TYPE: Optional[Activity] DEFAULT: None

initial_idle_since

The datetime to appear to be idle since, or None if the shard should not provide this. The default is None.

TYPE: Optional[datetime] DEFAULT: None

initial_is_afk

Whether to appear to be AFK or not on login.

TYPE: bool DEFAULT: False

initial_status

The initial status to set on login for the shard.

TYPE: Status DEFAULT: ONLINE

intents

Collection of intents to use.

TYPE: Intents

large_threshold

The number of members to have in a guild for it to be considered large.

TYPE: int DEFAULT: 250

shard_id

The shard ID.

TYPE: int DEFAULT: 0

shard_count

The shard count.

TYPE: int DEFAULT: 1

http_settings

The HTTP-related settings to use while negotiating a websocket.

TYPE: HTTPSettings

proxy_settings

The proxy settings to use while negotiating a websocket.

TYPE: ProxySettings

data_format

Data format to use for inbound data. Only supported format is "json".

TYPE: str DEFAULT: JSON

heartbeat_latency property #

heartbeat_latency: float

Shard's most recent heartbeat latency.

If the information is not yet available, then this will be float('nan') instead.

id property #

id: int

0-based shard ID for this shard.

intents property #

intents: Intents

Intents set on this shard.

is_alive property #

is_alive: bool

Whether the shard is alive.

is_connected property #

is_connected: bool

Whether the shard is connected.

shard_count property #

shard_count: int

Return the total number of shards expected in the entire application.

close async #

close() -> None

Close the websocket if it is connected.

get_user_id #

get_user_id() -> Snowflake

Return the user ID.

RETURNS DESCRIPTION
Snowflake

The user ID for the application user.

join async #

join() -> None

Wait indefinitely until the websocket closes.

This can be placed in a task and cancelled without affecting the websocket runtime itself.

request_guild_members async #

request_guild_members(guild: SnowflakeishOr[PartialGuild], *, include_presences: UndefinedOr[bool] = undefined.UNDEFINED, query: str = '', limit: int = 0, users: UndefinedOr[SnowflakeishSequence[User]] = undefined.UNDEFINED, nonce: UndefinedOr[str] = undefined.UNDEFINED) -> None

Request for a guild chunk.

Note

To request the full list of members, set query to "" (empty string) and limit to 0.

PARAMETER DESCRIPTION
guild

The guild to request chunk for.

TYPE: SnowflakeishOr[PartialGuild]

include_presences

If provided, whether to request presences.

TYPE: UndefinedOr[bool] DEFAULT: UNDEFINED

query

If not "", request the members which username starts with the string.

TYPE: str DEFAULT: ''

limit

Maximum number of members to send matching the query.

TYPE: int DEFAULT: 0

users

If provided, the users to request for.

TYPE: UndefinedOr[SnowflakeishSequence[User]] DEFAULT: UNDEFINED

nonce

If provided, the nonce to be sent with guild chunks.

TYPE: UndefinedOr[str] DEFAULT: UNDEFINED

RAISES DESCRIPTION
ValueError

If trying to specify users with query/limit, if limit is not between 0 and 100, both inclusive or if users length is over 100.

MissingIntentError

When trying to request presences without the hikari.intents.Intents.GUILD_MEMBERS or when trying to request the full list of members without hikari.intents.Intents.GUILD_PRESENCES.

start async #

start() -> None

Start the shard, wait for it to become ready.

update_presence async #

update_presence(*, idle_since: UndefinedNoneOr[datetime] = undefined.UNDEFINED, afk: UndefinedOr[bool] = undefined.UNDEFINED, activity: UndefinedNoneOr[Activity] = undefined.UNDEFINED, status: UndefinedOr[Status] = undefined.UNDEFINED) -> None

Update the presence of the shard user.

If the shard is not alive, no physical data will be sent, however, the new presence settings will be remembered for when the shard does connect.

PARAMETER DESCRIPTION
idle_since

The datetime that the user started being idle. If undefined, this will not be changed.

TYPE: UndefinedNoneOr[datetime] DEFAULT: UNDEFINED

afk

Whether to mark the user as AFK. If undefined, this will not be changed.

TYPE: UndefinedOr[bool] DEFAULT: UNDEFINED

activity

The activity to appear to be playing. If undefined, this will not be changed.

TYPE: UndefinedNoneOr[Activity] DEFAULT: UNDEFINED

status

The web status to show. If undefined, this will not be changed.

TYPE: UndefinedOr[Status] DEFAULT: UNDEFINED

update_voice_state async #

update_voice_state(guild: SnowflakeishOr[PartialGuild], channel: Optional[SnowflakeishOr[GuildVoiceChannel]], *, self_mute: UndefinedOr[bool] = undefined.UNDEFINED, self_deaf: UndefinedOr[bool] = undefined.UNDEFINED) -> None

Update the voice state for this shard in a given guild.

PARAMETER DESCRIPTION
guild

The guild or guild ID to update the voice state for.

TYPE: SnowflakeishOr[PartialGuild]

channel

The channel or channel ID to update the voice state for. If None then the bot will leave the voice channel that it is in for the given guild.

TYPE: Optional[SnowflakeishOr[GuildVoiceChannel]]

self_mute

If specified and True, the bot will mute itself in that voice channel. If False, then it will unmute itself.

TYPE: UndefinedOr[bool] DEFAULT: UNDEFINED

self_deaf

If specified and True, the bot will deafen itself in that voice channel. If False, then it will undeafen itself.

TYPE: UndefinedOr[bool] DEFAULT: UNDEFINED