Voice

discord_http.voice.client module

class discord_http.voice.client.VoiceClient(client, channel)

Bases: object

The public handle for an active voice connection in a guild.

Parameters:
bot: Client

The bot client that owns this voice client.

channel: PartialChannel

The voice channel this client is connected to.

guild_id: int

The ID of the guild this voice client is in.

connection: VoiceConnection

The underlying voice connection state machine.

property loop: AbstractEventLoop

The event loop the client runs on.

property user_id: int

The ID of the bot user.

property ssrc: int | None

The SSRC assigned to this connection.

property secret_key: bytes | None

The transport secret key, once known.

property latency: float

The latency of the most recent voice heartbeat, in seconds.

property average_latency: float

The average latency of recent voice heartbeats, in seconds.

property voice_privacy_code: str | None

The DAVE voice privacy code, if available.

property endpoint: str | None

The voice server endpoint host.

property session_id: str | None

The voice session ID.

is_connected() → bool

Whether the voice connection is established.

Return type:

bool

async connect(*, timeout=30.0, reconnect=True, reconnect_on_session_invalid=False, self_deaf=False, self_mute=False) → None

Connect to the voice channel.

Parameters:
  • timeout (float) – The maximum time to wait for the handshake, in seconds.

  • reconnect (bool) – Whether to attempt reconnection on failure.

  • reconnect_on_session_invalid (bool) – Whether to reconnect when Discord invalidates the session (close code 4006), e.g. after the channel empties and the DAVE session is torn down. Defaults to False (disconnect instead of reconnecting).

  • self_deaf (bool) – Whether to join self-deafened.

  • self_mute (bool) – Whether to join self-muted.

Return type:

None

async disconnect(*, force=True) → None

Disconnect from the voice channel and clean up.

Parameters:

force (bool) – Whether to force the disconnect even on error.

Return type:

None

async move_to(channel, *, timeout=10.0) → None

Move to a different voice channel.

Returns once Discord confirms the move, the voice connection then follows on its own.

Parameters:
  • channel (PartialChannel | int) – The channel to move to, either a channel object or its ID.

  • timeout (float) – How long to wait for Discord to confirm the move, in seconds.

Raises:
  • RuntimeError – If the voice client is not connected.

  • TimeoutError – If Discord didn’t move the bot, for example without permission to join the channel.

Return type:

None

on_voice_state_update(data) → None

Forward a VOICE_STATE_UPDATE to the connection.

Parameters:

data (dict) – The raw voice state update payload.

Return type:

None

on_voice_server_update(data) → None

Forward a VOICE_SERVER_UPDATE to the connection.

Parameters:

data (dict) – The raw voice server update payload.

Return type:

None

async speak(speaking=True) → None

Send the SPEAKING frame to the voice gateway.

Parameters:

speaking (bool) – Whether the bot is speaking.

Return type:

None

send_audio_packet(data, *, encode=True) → None

Frame, encrypt, and transmit a single audio packet over UDP.

Parameters:
  • data (bytes) – The audio payload: PCM when encode is True else a raw Opus packet.

  • encode (bool) – Whether data is PCM that must be Opus-encoded first.

Return type:

None

play(audio, *, after=None) → None

Play an audio source over the connection.

A string is handed to ffmpeg as its input, and ffmpeg opens whatever it names: local files, HTTP(S) and every other protocol it was built with. Do not pass text a user typed without checking it first, otherwise they can make the machine the bot runs on read its own files or reach hosts only it can see. ffmpeg can be limited to a set of protocols with before_options="-protocol_whitelist http,https,tcp,tls,crypto" on FFmpegOpusAudio or FFmpegPCMAudio.

Parameters:
Raises:

RuntimeError – If the voice client is not connected.

Return type:

None

pause() → None

Pause the current playback.

Return type:

None

resume() → None

Resume paused playback.

Return type:

None

stop() → None

Stop the current playback.

Return type:

None

is_playing() → bool

Whether audio is currently playing.

Return type:

bool

is_paused() → bool

Whether playback is currently paused.

Return type:

bool

listen(sink) → None

Start receiving voice into the given sink.

Parameters:

sink (AudioSink) – The audio sink to write received audio into.

Return type:

None

stop_listening() → None

Stop receiving voice.

Return type:

None

is_listening() → bool

Whether the client is currently receiving voice.

Return type:

bool

discord_http.voice.connection module

class discord_http.voice.connection.VoiceConnection(voice_client)

Bases: object

The transport and control-plane state machine for a voice connection.

Parameters:

voice_client (VoiceClient)

voice_client: VoiceClient

The voice client that owns this connection.

guild_id: int

The ID of the guild this connection is for.

channel_id: int | None

The ID of the voice channel currently targeted.

user_id: int

The ID of the bot user.

socket: VoiceSocket | None

The voice websocket, if open.

udp: VoiceUDPProtocol | None

The UDP protocol, if connected.

transport: DatagramTransport | None

The UDP datagram transport, if connected.

encryptor: Encryptor | None

The transport encryptor, once the secret key is known.

token: str | None

The voice connection token from the voice server update.

endpoint: str | None

The voice server endpoint host, without scheme or port.

session_id: str | None

The voice session ID from the voice state update.

server_id: int | None

The server (guild) ID from the voice server update.

ssrc: int | None

The synchronisation source identifier assigned by the gateway.

secret_key: bytes | None

The secret key used for transport encryption.

endpoint_ip: str | None

The discovered external IP address.

endpoint_port: int | None

The discovered external UDP port.

mode: str | None

The negotiated encryption mode.

sequence: int

The RTP sequence counter.

timestamp: int

The RTP timestamp counter.

dave_session: DaveManager | None

The DAVE/MLS session manager, if a protocol version was negotiated.

dave_protocol_version: int

The negotiated DAVE protocol version (0 if not in use).

connected_user_ids: set[int]

The users Discord reported in the call (ops 11 and 13), used to validate DAVE proposals.

property backoff: ExponentialBackoff

The exponential backoff for reconnects, built lazily from client settings.

property client: Client

The bot client that owns this voice connection.

property latency: float

The latency of the most recent voice heartbeat, in seconds.

property average_latency: float

The average latency of recent voice heartbeats, in seconds.

property voice_privacy_code: str | None

The DAVE voice privacy code, if a DAVE session is active.

is_connected() → bool

Whether the connection has completed its handshake.

Return type:

bool

async connect(*, timeout=30.0, reconnect=True, reconnect_on_session_invalid=False, self_deaf=False, self_mute=False) → None

Establish the full voice connection.

Parameters:
  • timeout (float) – The maximum time to wait for the handshake, in seconds.

  • reconnect (bool) – Whether to attempt reconnection on failure.

  • reconnect_on_session_invalid (bool) – Whether to reconnect when Discord invalidates the session (close code 4006), e.g. after the channel empties and the DAVE session is torn down. Defaults to False (disconnect instead of reconnecting).

  • self_deaf (bool) – Whether to join self-deafened.

  • self_mute (bool) – Whether to join self-muted.

Raises:
  • RuntimeError –

    • If no shard can be resolved for the guild - If DAVE is required but davey is not installed

  • TimeoutError – If the handshake does not complete within timeout.

  • VoiceConnectionClosed – If Discord closes the voice connection before it is established.

Return type:

None

on_voice_state_update(data) → None

Handle a VOICE_STATE_UPDATE for the bot.

Parameters:

data (dict) – The raw voice state update payload.

Return type:

None

on_voice_server_update(data) → None

Handle a VOICE_SERVER_UPDATE for the guild.

Parameters:

data (dict) – The raw voice server update payload.

Return type:

None

async on_ready(data) → None

Handle the voice READY (op 2): set up UDP and select the protocol.

Parameters:

data (dict) – The READY payload containing ssrc, ip, port and modes.

Return type:

None

async on_session_description(data) → None

Handle the SESSION_DESCRIPTION (op 4): build the encryptor.

Parameters:

data (dict) – The session description payload with the secret key and mode.

Return type:

None

async on_speaking(data) → None

Handle a SPEAKING (op 5) frame from another user.

Parameters:

data (dict) – The speaking payload with ssrc, user_id and speaking flags.

Return type:

None

async on_clients_connect(data) → None

Handle a CLIENTS_CONNECT (op 11) frame: remember who is in the call.

Parameters:

data (dict) – The payload with the user_ids that are connected.

Return type:

None

async on_client_disconnect(data) → None

Handle a CLIENT_DISCONNECT (op 13) frame: forget the user’s receive state.

Frees the SSRC mappings and per-SSRC Opus decoder held for the user, so a long-lived connection in a busy channel does not accumulate state for users who have left.

Parameters:

data (dict) – The client disconnect payload with the user_id that left.

Return type:

None

async on_resumed(data) → None

Handle the RESUMED (op 9) frame.

Parameters:

data (dict) – The resumed payload.

Return type:

None

async on_dave_binary(opcode, payload) → None

Handle an inbound binary DAVE frame.

Parameters:
  • opcode (int) – The voice opcode of the binary frame.

  • payload (bytes) – The binary payload following the opcode.

Return type:

None

async on_dave_json(opcode, data) → None

Handle an inbound JSON DAVE control op (transition/epoch, ops 21/22/24).

These ops arrive as JSON text frames rather than binary DAVE frames, so they carry the decoded d payload instead of raw bytes.

Parameters:
  • opcode (int) – The voice opcode of the control frame.

  • data (dict) – The decoded JSON d payload.

Return type:

None

async reinit_dave_session() → None

Create or reset the DAVE session for the negotiated protocol version.

Return type:

None

can_encrypt() → bool

Whether outgoing Opus payloads are end-to-end encrypted.

Return type:

bool

can_decrypt() → bool

Whether incoming Opus payloads are end-to-end encrypted and can be decrypted.

Return type:

bool

dave_encrypt_opus(opus) → bytes

Encrypt an Opus payload through the DAVE session, if active.

Parameters:

opus (bytes) – The Opus payload to encrypt.

Return type:

bytes

Returns:

The DAVE-encrypted Opus payload, or the input unchanged when inactive.

dave_decrypt_opus(user_id, opus) → bytes

Decrypt an Opus payload through the DAVE session, if active.

Parameters:
  • user_id (int) – The user ID the payload was received from.

  • opus (bytes) – The Opus payload to decrypt.

Return type:

bytes

Returns:

The decrypted Opus payload, or the input unchanged when inactive.

async disconnect(*, force=True) → None

Tear down the voice connection.

Parameters:

force (bool) – Whether to force the disconnect even if the gateway update fails.

Return type:

None

async close_transport() → None

Close the websocket and UDP transport without notifying the gateway.

Return type:

None

async move_to(channel, *, timeout=10.0) → None

Move the connection to a different voice channel.

Returns once Discord confirms the move, the voice connection then follows on its own.

Parameters:
  • channel (PartialChannel) – The channel to move to.

  • timeout (float) – How long to wait for Discord to confirm the move, in seconds.

Raises:
  • RuntimeError – If no shard can be resolved for the guild.

  • TimeoutError – If Discord didn’t move the bot, for example without permission to join.

Return type:

None

discord_http.voice.player module

class discord_http.voice.player.AudioPlayer(source, voice_client, *, after=None)

Bases: object

A drift-corrected asyncio.Task player that streams an AudioSource to a voice client.

Parameters:
DELAY: float = 0.02
start() → None

Schedule the playback task on the voice client’s event loop.

Return type:

None

stop() → None

Stop playback as soon as possible and resume any paused loop.

Return type:

None

pause() → None

Pause playback, halting reads until resume() is called.

Return type:

None

resume() → None

Resume playback after a pause().

Return type:

None

is_playing() → bool

Whether audio is currently playing (running and not paused).

Return type:

bool

is_paused() → bool

Whether playback is paused (running but paused).

Return type:

bool

set_source(source) → None

Hot-swap the audio source without interrupting the player task.

Parameters:

source (AudioSource) – The new audio source to read from.

Return type:

None

class discord_http.voice.player.AudioSource

Bases: ABC

An abstract audio source yielding one 20ms frame per read() (Opus packet or 3840-byte s16le PCM).

abstractmethod async read() → bytes

Read the next 20ms frame (Opus packet or 3840-byte PCM), or empty bytes at end of stream.

Return type:

bytes

is_opus() → bool

Whether read() yields pre-encoded Opus packets rather than PCM.

Return type:

bool

cleanup() → None

Release any resources held by the source.

Return type:

None

discord_http.voice.player.AudioSourceInput = discord_http.voice.player.AudioSource | str | os.PathLike | bytes | bytearray | memoryview | io.IOBase | collections.abc.AsyncIterable[bytes]

The set of inputs accepted as audio sources by VoiceClient.play().

class discord_http.voice.player.FFmpegOpusAudio(source, *, bitrate=128, before_options=None, options=None, pipe=False, executable='ffmpeg')

Bases: _FFmpegAudio

An audio source that encodes input to Opus with ffmpeg, extracting raw packets from its Ogg/Opus stream.

Parameters:
async read() → bytes

Read one Opus packet from ffmpeg’s Ogg stream, or empty bytes at EOF.

Return type:

bytes

is_opus() → bool

Whether frames are Opus packets (always True for this source).

Return type:

bool

cleanup() → None

Terminate the ffmpeg subprocess and cancel the stdin pump.

Return type:

None

class discord_http.voice.player.FFmpegPCMAudio(source, *, before_options=None, options=None, pipe=False, executable='ffmpeg')

Bases: _FFmpegAudio

An audio source that transcodes input to s16le 48kHz stereo PCM with ffmpeg (libopus needed to encode).

Parameters:
async read() → bytes

Read one 3840-byte PCM frame from ffmpeg, or empty bytes at EOF.

Return type:

bytes

cleanup() → None

Terminate the ffmpeg subprocess and cancel the stdin pump.

Return type:

None

is_opus() → bool

Whether read() yields pre-encoded Opus packets rather than PCM.

Return type:

bool

class discord_http.voice.player.PCMAudio(stream)

Bases: AudioSource

An audio source that reads raw s16le 48kHz stereo PCM frames from a binary stream.

Parameters:

stream (IOBase)

async read() → bytes

Read one 3840-byte PCM frame, or empty bytes at end of stream.

Return type:

bytes

cleanup() → None

Release any resources held by the source.

Return type:

None

is_opus() → bool

Whether read() yields pre-encoded Opus packets rather than PCM.

Return type:

bool

class discord_http.voice.player.PCMVolumeTransformer(original, volume=1.0)

Bases: AudioSource

A wrapper that scales the volume of a PCM (non-Opus) audio source using the stdlib array module.

Parameters:
property volume: float

The volume multiplier, where 1.0 is unchanged.

async read() → bytes

Read one frame from the wrapped source with volume applied.

Return type:

bytes

cleanup() → None

Clean up the wrapped source.

Return type:

None

is_opus() → bool

Whether read() yields pre-encoded Opus packets rather than PCM.

Return type:

bool

discord_http.voice.receiver module

class discord_http.voice.receiver.VoiceReceiver(voice_client)

Bases: object

Consumes incoming RTP voice packets and dispatches audio to an AudioSink.

Parameters:

voice_client (VoiceClient)

voice_client

The voice client this receiver belongs to.

sink: AudioSink | None

The sink currently receiving audio, or None when not listening.

start(sink) → None

Begin listening, dispatching received audio to sink.

Parameters:

sink (AudioSink) – The sink to receive decoded PCM or raw Opus audio.

Return type:

None

stop() → None

Stop listening and release any per-SSRC decoders and the sink.

Return type:

None

reset() → None

Drop all SSRC-keyed state for a fresh voice session.

Called on voice READY, where a fresh session has just allocated new SSRCs. Separate from stop() because stop() also detaches and finalizes the sink. A reconnect must keep listening with the existing sink while forgetting mappings, decoders and sequence state tied to SSRCs from the previous session.

Return type:

None

is_listening() → bool

Whether a sink is currently attached.

Return type:

bool

add_ssrc(ssrc, user_id) → None

Associate an RTP SSRC with a user ID.

Parameters:
  • ssrc (int) – The RTP synchronisation source identifier.

  • user_id (int) – The user ID that owns the SSRC.

Return type:

None

remove_user(user_id) → None

Remove every SSRC mapping and decoder belonging to a user.

Parameters:

user_id (int) – The user ID to forget.

Return type:

None

unpack(packet) → None

Decrypt, decode and dispatch a single received RTP packet.

This is called synchronously from the UDP datagram callback, so it must never raise: every failure is logged and swallowed.

Parameters:

packet (bytes) – The raw RTP packet as received from the voice UDP socket.

Return type:

None

discord_http.voice.sinks module

class discord_http.voice.sinks.AudioSink

Bases: ABC

Abstract base class for consumers of received voice audio.

wants_opus() → bool

Whether this sink wants raw Opus payloads instead of decoded PCM.

When False (the default) the receiver decodes packets to PCM before handing them to write().

Return type:

bool

abstractmethod write(user, data) → None

Consume a single chunk of received voice audio.

Parameters:
  • user (int | None) – The user ID the audio belongs to, or None if unknown

  • data (VoiceData) – The voice data container holding the PCM and/or Opus payload

Return type:

None

cleanup() → None

Finalize the sink, flushing and releasing any held resources.

Return type:

None

class discord_http.voice.sinks.CallbackSink(callback, *, opus=False)

Bases: AudioSink

Audio sink that forwards every received chunk to a callback.

Parameters:
wants_opus() → bool

Whether this sink wants raw Opus payloads instead of decoded PCM.

Return type:

bool

write(user, data) → None

Forward the received audio chunk to the callback.

Parameters:
  • user (int | None) – The user ID the audio belongs to, or None if unknown

  • data (VoiceData) – The voice data container holding the PCM and/or Opus payload

Return type:

None

cleanup() → None

Finalize the sink, flushing and releasing any held resources.

Return type:

None

class discord_http.voice.sinks.VoiceData(user, pcm, opus, timestamp, ssrc)

Bases: object

Represents a single chunk of received voice audio for one speaker.

Parameters:
user: int | None

The user ID this audio belongs to, or None if unknown.

pcm: bytes | None

The decoded 48kHz 16-bit stereo PCM payload, if available.

opus: bytes | None

The raw Opus payload, if available.

timestamp: int

The RTP timestamp of the packet this data came from.

ssrc: int

The RTP SSRC of the sender this data came from.

class discord_http.voice.sinks.WaveSink(destination)

Bases: AudioSink

Audio sink that writes received PCM to a single 48kHz 16-bit stereo WAV file.

Audio from all speakers is appended to the one stream in arrival order; it is not mixed. With a single speaker this produces a normal recording, but simultaneous speakers will have their chunks interleaved back-to-back and sound garbled. To handle overlapping speakers, separate the audio per user first (for example with a CallbackSink that routes each user to its own file) and mix the results afterwards.

Parameters:

destination (str | PathLike | IOBase)

wants_opus() → bool

Whether this sink wants raw Opus payloads instead of decoded PCM.

Return type:

bool

write(user, data) → None

Append the chunk’s PCM payload to the WAV file.

Parameters:
  • user (int | None) – The user ID the audio belongs to, or None if unknown (unused; chunks from all speakers are appended to the same WAV stream in arrival order, without mixing)

  • data (VoiceData) – The voice data container holding the PCM payload

Return type:

None

cleanup() → None

Finalize the WAV file, writing headers and closing the stream.

Return type:

None

discord_http.voice.dave module

class discord_http.voice.dave.DaveManager(connection)

Bases: object

Manages DAVE (E2EE) for a voice connection, degrading to a no-op when davey is absent.

Parameters:

connection (VoiceConnection)

property ready: bool

Whether the underlying MLS session has completed its handshake.

property voice_privacy_code: str | None

The privacy code users can compare out-of-band to verify the E2EE session, if any.

can_encrypt() → bool

Whether outgoing audio is end-to-end encrypted, which starts once a transition is executed.

Return type:

bool

can_decrypt() → bool

Whether incoming audio can be end-to-end decrypted, which starts once a transition is prepared.

Return type:

bool

remove_user(user_id) → None

Forget per-user state for a user that left the call.

Parameters:

user_id (int) – The user that left.

Return type:

None

async reinit(version) → None

Create or reinitialise the MLS session for a given protocol version.

When version is greater than 0 but davey is not installed, a clear, actionable RuntimeError is raised telling the user how to install the optional dependency. When a session is created, its serialized MLS key package is sent to the voice gateway.

Parameters:

version (int) – The negotiated DAVE protocol version. 0 disables end-to-end encryption.

Raises:

RuntimeError – If a non-zero DAVE version is requested but davey is not installed.

Return type:

None

set_passthrough_mode(enabled, expiry=None) → None

Toggle passthrough mode on the MLS session.

While in passthrough mode the session does not transform media, allowing audio to flow during transitions where some participants are not yet on the new epoch.

Parameters:
  • enabled (bool) – True to pass media through unchanged, False to resume encryption.

  • expiry (int | None) – How long, in seconds, plaintext keeps being accepted after the change. None uses davey’s default.

Return type:

None

encrypt_opus(opus) → bytes

End-to-end encrypt an outbound Opus frame.

Parameters:

opus (bytes) – The plaintext Opus frame.

Return type:

bytes

Returns:

The encrypted frame, or the input unchanged when E2EE is not active.

decrypt_opus(user_id, opus) → bytes

End-to-end decrypt an inbound Opus frame from a given user.

Parameters:
  • user_id (int) – The user the frame originated from.

  • opus (bytes) – The received Opus frame.

Return type:

bytes

Returns:

The decrypted frame, or the input unchanged when E2EE is not active.

async handle_binary(opcode, payload) → None

Dispatch a binary DAVE/MLS operation (opcodes 21-31) received from the gateway.

Parameters:
  • opcode (int) – The voice opcode, expected to be one of the DAVE ops 21-31.

  • payload (bytes) – The raw binary payload following the opcode.

Return type:

None

async handle_json(opcode, data) → None

Dispatch a JSON DAVE control op (21, 22, 24) received from the gateway.

Unlike the MLS data ops (25-31), the transition/epoch control ops arrive as regular JSON text frames rather than binary frames, so they are routed here with the decoded d payload instead of raw bytes.

Parameters:
  • opcode (int) – The voice opcode, expected to be one of 21, 22 or 24.

  • data (dict) – The decoded JSON d payload of the frame.

Return type:

None

discord_http.voice.dave.max_protocol_version() → int

The maximum DAVE protocol version this installation can negotiate (0 if davey is absent).

Return type:

int

discord_http.voice.opus module

discord_http.voice.opus.OPUS_SILENCE = b'\xf8\xff\xfe'

The magic Opus frame that encodes silence.

discord_http.voice.opus.SAMPLES_PER_FRAME = 960

The number of samples per channel in a single 20ms frame (960).

discord_http.voice.opus.SAMPLE_RATE = 48000

The sample rate Discord expects, in Hz.

class discord_http.voice.opus.Decoder

Bases: object

A libopus decoder configured for Discord voice (48kHz, stereo).

static packet_get_nb_frames(data) → int

Return the number of frames in an Opus packet.

Parameters:

data (bytes) – The Opus packet to inspect.

Return type:

int

Returns:

The number of frames the packet contains.

static packet_get_samples_per_frame(data) → int

Return the number of samples per frame for an Opus packet.

Parameters:

data (bytes) – The Opus packet to inspect.

Return type:

int

Returns:

The number of samples per channel in each frame.

decode(data, *, fec=False) → bytes

Decode an Opus packet into PCM audio.

Parameters:
  • data (bytes | None) – The Opus packet to decode, or None to perform packet-loss concealment for a single 20ms frame.

  • fec (bool) – Whether to decode using forward error correction.

Return type:

bytes

Returns:

The decoded signed 16-bit little-endian stereo PCM data.

Raises:

OpusError – If libopus fails to decode the packet.

cleanup() → None

Free the underlying libopus decoder.

Return type:

None

class discord_http.voice.opus.Encoder(application=2049)

Bases: object

A libopus encoder configured for Discord voice (48kHz, stereo).

Parameters:

application (int)

application

The Opus application type the encoder was created with.

encode(pcm, frame_size=960) → bytes

Encode a single frame of PCM audio into an Opus packet.

Parameters:
  • pcm (bytes) – The raw signed 16-bit little-endian stereo PCM data.

  • frame_size (int) – The number of samples per channel in the frame.

Return type:

bytes

Returns:

The encoded Opus packet.

Raises:

OpusError –

  • If pcm is not exactly one frame long - If libopus fails to encode the frame

cleanup() → None

Free the underlying libopus encoder.

Return type:

None

exception discord_http.voice.opus.OpusError

Bases: DiscordException

Raised when libopus returns an error code.

add_note(object, /)

Exception.add_note(note) – add a note to the exception

args
with_traceback(object, /)

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception discord_http.voice.opus.OpusNotLoaded

Bases: DiscordException

Raised when an Opus operation is attempted but libopus is not available.

add_note(object, /)

Exception.add_note(note) – add a note to the exception

args
with_traceback(object, /)

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

discord_http.voice.opus.is_loaded() → bool

Whether libopus is currently loaded, attempting a lazy load once if not yet tried.

Return type:

bool

discord_http.voice.opus.load_opus(name=None) → None

Load libopus and configure all of its bindings.

Parameters:

name (str | None) – An explicit path or library name to load. When omitted, the system library is located with ctypes.util.find_library().

Raises:

OpusError – If an explicit name was given but the library could not be loaded.

Return type:

None

discord_http.voice.enums module

class discord_http.voice.enums.VoiceOpType(*values)

Bases: BaseEnum

Represents the opcode type of a voice gateway payload.

identify = 0
select_protocol = 1
ready = 2
heartbeat = 3
session_description = 4
speaking = 5
heartbeat_ack = 6
resume = 7
hello = 8
resumed = 9
clients_connect = 11
client_disconnect = 13
dave_prepare_transition = 21
dave_execute_transition = 22
dave_transition_ready = 23
dave_prepare_epoch = 24
dave_mls_external_sender = 25
dave_mls_key_package = 26
dave_mls_proposals = 27
dave_mls_commit_welcome = 28
dave_mls_announce_commit_transition = 29
dave_mls_welcome = 30
dave_mls_invalid_commit_welcome = 31
property pretty_name: str

A prettified version of the enum name.

classmethod random() → Self

Return a random enum.

Return type:

Self

classmethod try_get(key, default=None) → Optional[Self]

Try to get an enum member by name or value, returning a default if not found.

Parameters:
  • key (str | int | None) – The name or value of the enum member to retrieve.

  • default (Optional[Self]) – The value to return if the key is not found.

Return type:

Optional[Self]

Returns:

The enum member if found, otherwise the default value.

classmethod names() → list[str]

Return a list of all enum names.

Return type:

list[str]

classmethod values() → list[int | str]

Return a list of all enum values.

Return type:

list[int | str]

classmethod to_dict() → dict[str, int | str]

Return a dictionary mapping names to values.

Return type:

dict[str, int | str]