Skip to content

hikari.api.voice#

Interfaces used to describe voice client implementations.

VoiceComponent #

Bases: ABC

Interface for a voice system implementation.

connections abstractmethod property #

Return a mapping of guild-id to active voice connection.

is_alive abstractmethod property #

is_alive: bool

Whether this component is alive.

close abstractmethod async #

close() -> None

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 hikari.api.VoiceComponent.disconnect instead.

connect_to abstractmethod async #

connect_to(
    guild: SnowflakeishOr[Guild],
    channel: SnowflakeishOr[GuildVoiceChannel],
    voice_connection_type: Type[_VoiceConnectionT],
    *,
    deaf: bool = False,
    mute: bool = False,
    timeout: Optional[int] = 5,
    **kwargs: Any
) -> _VoiceConnectionT

Connect to a given voice channel.

PARAMETER DESCRIPTION
guild

The guild to connect to.

TYPE: SnowflakeishOr[Guild]

channel

The channel or channel ID to connect to.

TYPE: SnowflakeishOr[GuildVoiceChannel]

voice_connection_type

The type of voice connection to use. This should be initialized internally using the hikari.api.voice.VoiceConnection.initialize classmethod.

TYPE: Type[VoiceConnection]

deaf

If True, the client will enter the voice channel deafened (thus unable to hear other users).

TYPE: bool DEFAULT: False

mute

If True, the client will enter the voice channel muted (thus unable to send audio).

TYPE: bool DEFAULT: False

timeout

The amount of time, in seconds, to wait before erroring when connecting to the voice channel. If timeout is None there will be no timeout.

Warning

If timeout is None, this function will be awaited forever if an invalid guild_id or channel_id is provided.

TYPE: Optional[int] DEFAULT: 5

**kwargs

Any arguments to provide to the hikari.api.voice.VoiceConnection.initialize method.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
VoiceConnection

A voice connection implementation of some sort.

disconnect abstractmethod async #

disconnect(guild: SnowflakeishOr[PartialGuild]) -> None

Disconnect from a given guild.

PARAMETER DESCRIPTION
guild

The guild to disconnect from.

TYPE: SnowflakeishOr[Guild]

disconnect_all abstractmethod async #

disconnect_all() -> None

Disconnect all the active voice connections.

VoiceConnection #

Bases: 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.

channel_id abstractmethod property #

channel_id: Snowflake

ID of the voice channel this voice connection is in.

guild_id abstractmethod property #

guild_id: Snowflake

ID of the guild this voice connection is in.

is_alive abstractmethod property #

is_alive: bool

Whether the connection is alive.

owner abstractmethod property #

Return the component that is managing this connection.

shard_id abstractmethod property #

shard_id: int

ID of the shard that requested the connection.

disconnect abstractmethod async #

disconnect() -> None

Signal the process to shut down.

initialize abstractmethod async classmethod #

initialize(
    channel_id: Snowflake,
    endpoint: str,
    guild_id: Snowflake,
    on_close: Callable[[Self], Awaitable[None]],
    owner: VoiceComponent,
    session_id: str,
    shard_id: int,
    token: str,
    user_id: Snowflake,
    **kwargs: Any
) -> Self

Initialize and connect the voice connection.

PARAMETER DESCRIPTION
channel_id

The channel ID that the voice connection is actively connected to.

TYPE: Snowflake

endpoint

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).

TYPE: str

guild_id

The guild ID that the websocket should connect to.

TYPE: Snowflake

on_close

A shutdown hook to invoke when closing a connection to ensure the connection is unregistered from the voice component safely.

TYPE: Callable[[T], Awaitable[None]]

owner

The component that made this connection object.

TYPE: VoiceComponent

session_id

The voice session ID to use.

TYPE: str

shard_id

The associated shard ID that the voice connection was generated from.

TYPE: int

token

The voice token to use.

TYPE: str

user_id

The user ID of the account that just joined the voice channel.

TYPE: Snowflake

**kwargs

Any implementation-specific arguments to provide to the voice connection that is being initialized.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
VoiceConnection

The type of this connection object.

join abstractmethod async #

join() -> None

Wait for the process to halt before continuing.

notify abstractmethod async #

notify(event: VoiceEvent) -> None

Submit an event to the voice connection to be processed.