Skip to content

~.gateway

Gateway

GatewayPayload

Base payload implementation.

GatewayReadyPayload dataclass

GatewayReadyPayload(
    ip: str, modes: list[str], port: int, ssrc: int
)

Bases: GatewayPayload

Voice gateway READY operation payload.

ip instance-attribute

ip: str

The Discord voice server IP address to connect to.

modes instance-attribute

modes: list[str]

All acceptable encryption modes that Discord's voice server supports.

port instance-attribute

port: int

The Discord voice server port to connect to.

ssrc instance-attribute

ssrc: int

The voice SSRC assigned by Discord for voice packets.

GatewayReport dataclass

GatewayReport(
    signal: (
        DisconnectSignal | ReconnectSignal | ResumeSignal
    ),
)

A connection report from the voice gateway.

signal instance-attribute

The signal raised by the voice gateway.

GatewaySessionDescriptionPayload dataclass

GatewaySessionDescriptionPayload(
    dave_protocol_version: int, mode: str, secret: bytes
)

Bases: GatewayPayload

Voice gateway SESSION_DESCRIPTION payload.

dave_protocol_version instance-attribute

dave_protocol_version: int

The initial DAVE protocol version the Discord voice server will use.

mode instance-attribute

mode: str

The encryption mode that audio packets should be encrypted with.

secret instance-attribute

secret: bytes

The secret key used to encrypt/decrypt audio packets.

GatewayState

Bases: IntEnum

Current state of a voice gateway.

CONNECTED class-attribute instance-attribute

CONNECTED = 0

Voice gateway is connected.

CONNECTING class-attribute instance-attribute

CONNECTING = 1

Voice gateway is connecting.

DISCONNECTED class-attribute instance-attribute

DISCONNECTED = 2

Voice gateway is not connected.

DISCONNECTING class-attribute instance-attribute

DISCONNECTING = 3

Voice gateway is disconnecting.

VoiceGateway

VoiceGateway(connection: VoiceConnection)

Discord voice gateway connection manager.

Create a Discord voice gateway connection manager.

PARAMETER DESCRIPTION
connection

The active voice connection.

TYPE: VoiceConnection

connect async

connect(url: str) -> None

Connect to a Discord voice gateway endpoint.

PARAMETER DESCRIPTION
url

The websocket URL to Discord's voice gateway.

TYPE: str

disconnect async

disconnect() -> None

Disconnect from Discord's voice gateway.

select_protocol async

select_protocol(ip: str, port: int, mode: str) -> None

Send the SELECT_PROTOCOL operation payload to Discord's voice gateway.

PARAMETER DESCRIPTION
ip

This device's IPv4 address.

TYPE: str

port

The port for Discord's voice server to communicate with this device.

TYPE: int

mode

The desired encryption method to use with Discord's voice server.

TYPE: str

set_callback

set_callback(
    opcode: Opcode,
    callback: Callable[
        [GatewayPayload], Coroutine[Any, Any, None]
    ],
) -> None

Set a callback method for the arrival of a specific voice gateway operation code.

PARAMETER DESCRIPTION
opcode

The voice gateway operation code to listen for.

TYPE: Opcode

callback

The asynchronous method to call as the callback with the payload of this operation.

TYPE: Callable[[GatewayPayload], Coroutine[Any, Any, None]]

set_speaking async

set_speaking(state: bool, priority: bool = False) -> None

Set our SPEAKING state.

PARAMETER DESCRIPTION
state

If we are speaking.

TYPE: bool

priority

If we should speak with PRIORITY status.

TYPE: bool DEFAULT: False