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
, andinitial_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:
- token
str
The bot token to use.
- url
str
The gateway URL to use. This should not contain a query-string or fragments.
- event_manager
hikari.api.event_manager.EventManager
The event manager this shard should make calls to.
- event_factory
hikari.api.event_factory.EventFactory
The event factory this shard should use.
- token
- Other Parameters:
- compression
typing.Optional
[str
] Compression format to use for the shard. Only supported values are
"transport_zlib_stream"
orNone
to disable it.- initial_activity
typing.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_since
typing.Optional
[datetime.datetime
] The datetime to appear to be idle since, or
None
if the shard should not provide this. The default isNone
.- initial_is_afkbool
Whether to appear to be AFK or not on login. Defaults to
False
.- initial_status
hikari.presences.Status
The initial status to set on login for the shard. Defaults to
hikari.presences.Status.ONLINE
.- intents
hikari.intents.Intents
Collection of intents to use.
- large_threshold
int
The number of members to have in a guild for it to be considered large.
- shard_id
int
The shard ID.
- shard_count
int
The shard count.
- http_settings
hikari.impl.config.HTTPSettings
The HTTP-related settings to use while negotiating a websocket.
- proxy_settings
hikari.impl.config.ProxySettings
The proxy settings to use while negotiating a websocket.
- data_format
str
Data format to use for inbound data. Only supported format is
"json"
.
- compression
- 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 intents: hikari.intents.Intents[source]#
Intents set on this shard.
- property shard_count: int[source]#
Return the total number of shards expected in the entire application.
- 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) andlimit
to0
.- Parameters:
- guild
hikari.guilds.Guild
The guild to request chunk for.
- guild
- Other Parameters:
- include_presences
hikari.undefined.UndefinedOr
[bool] If provided, whether to request presences.
- query
str
If not
""
, request the members which username starts with the string.- limit
int
Maximum number of members to send matching the query.
- users
hikari.undefined.UndefinedOr
[hikari.snowflakes.SnowflakeishSequence
[hikari.users.User
]] If provided, the users to request for.
- nonce
hikari.undefined.UndefinedOr
[str
] If provided, the nonce to be sent with guild chunks.
- include_presences
- Raises:
ValueError
When trying to specify
users
withquery
/limit
, iflimit
is not between 0 and 100, both inclusive or ifusers
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 withoutGUILD_PRESENCES
.
- 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_since
hikari.undefined.UndefinedNoneOr
[datetime.datetime
] The datetime that the user started being idle. If undefined, this will not be changed.
- afk
hikari.undefined.UndefinedOr
[bool] If
True
, the user is marked as AFK. IfFalse
, the user is marked as being active. If undefined, this will not be changed.- activity
hikari.undefined.UndefinedNoneOr
[hikari.presences.Activity
] The activity to appear to be playing. If undefined, this will not be changed.
- status
hikari.undefined.UndefinedOr
[hikari.presences.Status
] The web status to show. If undefined, this will not be changed.
- idle_since
- 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:
- guild
hikari.snowflakes.SnowflakeishOr
[hikari.guilds.PartialGuild
] The guild or guild ID to update the voice state for.
- channel
typing.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. IfFalse
, then it will unmute itself.- self_deafbool
If specified and
True
, the bot will deafen itself in that voice channel. IfFalse
, then it will undeafen itself.
- guild