hikari.api.voice#
Interfaces used to describe voice client implementations.
Module Contents#
- class hikari.api.voice.VoiceComponent[source]#
Bases:
abc.ABC
Interface for a voice system implementation.
- abstract property connections: Mapping[hikari.snowflakes.Snowflake, VoiceConnection][source]#
Return a mapping of guild-id to active voice connection.
- abstract async close()[source]#
Shut down all connections, waiting for them to terminate.
Once this is done, unsubscribe from any events.
If you simply wish to disconnect every connection, use
disconnect
instead.
- abstract async connect_to(guild, channel, voice_connection_type, *, deaf=False, mute=False, timeout=5, **kwargs)[source]#
Connect to a given voice channel.
- Parameters:
- guild
hikari.snowflakes.SnowflakeishOr
[hikari.guilds.Guild
] The guild to connect to.
- channel
hikari.snowflakes.SnowflakeishOr
[hikari.channels.GuildVoiceChannel
] The channel or channel ID to connect to.
- voice_connection_type
typing.Type
[VoiceConnection
] The type of voice connection to use. This should be initialized internally using the
VoiceConnection.initialize
classmethod
.- deafbool
Defaulting to
False
, ifTrue
, the client will enter the voice channel deafened (thus unable to hear other users).- mutebool
Defaulting to
False
, ifTrue
, the client will enter the voice channel muted (thus unable to send audio).- timeout
typing.Optional
[int
] Defaulting to
5
, The amount of time to wait before erroring when connecting to the voice channel. If timeout isNone
there will be no timeout.Warning
If timeout is
None
, this function will be awaited forever if an invalidguild_id
orchannel_id
is provided.- **kwargs
typing.Any
Any arguments to provide to the
VoiceConnection.initialize
method.
- guild
- Returns:
VoiceConnection
A voice connection implementation of some sort.
- abstract async disconnect(guild)[source]#
Disconnect from a given guild.
- Parameters:
- guild
hikari.snowflakes.SnowflakeishOr
[hikari.guilds.Guild
] The guild to disconnect from.
- guild
- class hikari.api.voice.VoiceConnection[source]#
Bases:
abc.ABC
An abstract interface for defining how bots can interact with voice.
Since voice will generally be run in a subprocess to prevent interfering with the bot when performing CPU-bound encoding/encryption, any implementation of this is expected to implement the appropriate mechanisms for communicating with a voice subprocess and controlling it, however, this is left to the discretion of each implementation.
Control is left to the implementation to define how to perform it. The idea is to allow various decoders to be implemented to allow this to direct interface with other types of system outside this library, such as LavaLink, for example.
- abstract property channel_id: hikari.snowflakes.Snowflake[source]#
ID of the voice channel this voice connection is in.
- abstract property guild_id: hikari.snowflakes.Snowflake[source]#
ID of the guild this voice connection is in.
- abstract property owner: VoiceComponent[source]#
Return the component that is managing this connection.
- abstract async classmethod initialize(channel_id, endpoint, guild_id, on_close, owner, session_id, shard_id, token, user_id, **kwargs)[source]#
Initialize and connect the voice connection.
- Parameters:
- channel_id
hikari.snowflakes.Snowflake
The channel ID that the voice connection is actively connected to.
- endpoint
str
The voice websocket endpoint to connect to. Will contain the protocol at the start (i.e.
wss://
), and end with the correct port (the port and protocol are sanitized since Discord still provide the wrong information four years later).- guild_id
hikari.snowflakes.Snowflake
The guild ID that the websocket should connect to.
- on_close
typing.Callable
[[T
],typing.Awaitable
[None
]] A shutdown hook to invoke when closing a connection to ensure the connection is unregistered from the voice component safely.
- owner
VoiceComponent
The component that made this connection object.
- session_id
str
The voice session ID to use.
- shard_id
int
The associated shard ID that the voice connection was generated from.
- token
str
The voice token to use.
- user_id
hikari.snowflakes.Snowflake
The user ID of the account that just joined the voice channel.
- **kwargs
typing.Any
Any implementation-specific arguments to provide to the voice connection that is being initialized.
- channel_id
- Returns:
VoiceConnection
The type of this connection object.