Star ✨ on GitHub

Voice

Manages the Discord voice connection lifecycle, handling state updates, server updates, and automatic reconnection logic.

The Voice class handles the low-level details of connecting to a Discord voice channel. It listens for voice server/state updates from Discord and forwards the necessary credentials (session ID, token, endpoint) to the Lavalink node to establish the audio stream.

Properties

Voice Properties

Internal state of the voice connection.

Connection Info

playerPlayer

The player instance this voice connection belongs to.

sessionIdstring | null

The session ID received from Discord VOICE_STATE_UPDATE.

tokenstring | null

The token received from Discord VOICE_SERVER_UPDATE.

endpointstring | null

The voice server endpoint received from Discord.

State

stateVoiceConnectionState

Current connection state (DISCONNECTED, CONNECTING, CONNECTED, DESTROYED).

isMovingboolean

True if the player is currently moving between voice channels.

Methods

connect(options)

connect(options)#

Initiates the connection handshake with Discord. Sends the Gateway Opcode 4 payload.

optionsobject

Configuration for the connection.

options

selfDeafboolean required

Whether to join deafened.

selfMuteboolean required

Whether to join muted.

Example
await player.voice.connect({ selfDeaf: true, selfMute: false });

disconnect()

disconnect()#

Disconnects from the voice channel by sending an Opcode 4 payload with a null channel ID.

Example
await player.voice.disconnect();

destroy()

destroy()#

Marks the voice connection as destroyed and cleans up listeners.

Example
player.voice.destroy();

check(connected)

Checks the connection health. If the connection has failed multiple times consecutively, it triggers a recovery attempt.

connectedboolean required

Whether the player is currently considered connected by the node.

handleStateUpdate(data)

handleStateUpdate(data)#

Internal method to handle VOICE_STATE_UPDATE packets from Discord. Updates the session ID and channel ID.

dataobject required

The raw packet data.

handleServerUpdate(data)

Internal method to handle VOICE_SERVER_UPDATE packets from Discord. Updates the token and endpoint.

dataobject required

The raw packet data.