hikari.impl.shard#

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

Module Contents#

class hikari.impl.shard.GatewayShardImpl(*, compression=shard.GatewayCompression.TRANSPORT_ZLIB_STREAM, initial_activity=None, initial_idle_since=None, initial_is_afk=False, initial_status=presences.Status.ONLINE, intents, large_threshold=250, shard_id=0, shard_count=1, http_settings, proxy_settings, data_format=shard.GatewayDataFormat.JSON, event_manager, event_factory, token, url)[source]#

Bases: hikari.api.shard.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.

Parameters
tokenstr

The bot token to use.

urlstr

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

event_managerhikari.api.event_manager.EventManager

The event manager this shard should make calls to.

event_factoryhikari.api.event_factory.EventFactory

The event factory this shard should use.

Other Parameters
compressiontyping.Optional[str]

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

initial_activitytyping.Optional[hikari.presences.Activity]

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

initial_idle_sincetyping.Optional[datetime.datetime]

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

initial_is_afkbool

Whether to appear to be AFK or not on login. Defaults to False.

initial_statushikari.presences.Status

The initial status to set on login for the shard. Defaults to hikari.presences.Status.ONLINE.

intentshikari.intents.Intents

Collection of intents to use.

large_thresholdint

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

shard_idint

The shard ID.

shard_countint

The shard count.

http_settingshikari.impl.config.HTTPSettings

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

proxy_settingshikari.impl.config.ProxySettings

The proxy settings to use while negotiating a websocket.

data_formatstr

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

property heartbeat_latency: float[source]#

Shard’s most recent heartbeat latency.

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

property id: int[source]#

0-based shard ID for this shard.

property intents: hikari.intents.Intents[source]#

Intents set on this shard.

property is_alive: bool[source]#

Whether the shard is alive.

property is_connected: bool[source]#

Whether the shard is connected.

property shard_count: int[source]#

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

async close()[source]#

Close the websocket if it is connected.

get_user_id()[source]#

Return the user ID.

Returns
hikari.snowflakes.Snowflake

The user ID for the application user.

async join()[source]#

Wait indefinitely until the websocket closes.

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

async request_guild_members(guild, *, include_presences=undefined.UNDEFINED, query='', limit=0, users=undefined.UNDEFINED, nonce=undefined.UNDEFINED)[source]#

Request for a guild chunk.

Note

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

Parameters
guildhikari.guilds.Guild

The guild to request chunk for.

Other Parameters
include_presenceshikari.undefined.UndefinedOr[bool]

If provided, whether to request presences.

querystr

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

limitint

Maximum number of members to send matching the query.

usershikari.undefined.UndefinedOr[hikari.snowflakes.SnowflakeishSequence[hikari.users.User]]

If provided, the users to request for.

noncehikari.undefined.UndefinedOr[str]

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

Raises
ValueError

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

hikari.errors.MissingIntentError

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

async start()[source]#

Start the shard, wait for it to become ready.

async update_presence(*, idle_since=undefined.UNDEFINED, afk=undefined.UNDEFINED, activity=undefined.UNDEFINED, status=undefined.UNDEFINED)[source]#

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.

Other Parameters
idle_sincehikari.undefined.UndefinedNoneOr[datetime.datetime]

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

afkhikari.undefined.UndefinedOr[bool]

If True, the user is marked as AFK. If False, the user is marked as being active. If undefined, this will not be changed.

activityhikari.undefined.UndefinedNoneOr[hikari.presences.Activity]

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

statushikari.undefined.UndefinedOr[hikari.presences.Status]

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

async update_voice_state(guild, channel, *, self_mute=undefined.UNDEFINED, self_deaf=undefined.UNDEFINED)[source]#

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

Parameters
guildhikari.snowflakes.SnowflakeishOr[hikari.guilds.PartialGuild]

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

channeltyping.Optional[hikari.snowflakes.SnowflakeishOr[hikari.channels.GuildVoiceChannel]]

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.

self_mutebool

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

self_deafbool

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