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
The player instance this voice connection belongs to.
The session ID received from Discord VOICE_STATE_UPDATE.
The token received from Discord VOICE_SERVER_UPDATE.
The voice server endpoint received from Discord.
State
Current connection state (DISCONNECTED, CONNECTING, CONNECTED, DESTROYED).
True if the player is currently moving between voice channels.
Methods
connect(options)
connect(options)#
→Promise<void>Initiates the connection handshake with Discord. Sends the Gateway Opcode 4 payload.
Configuration for the connection.
options
Whether to join deafened.
Whether to join muted.
disconnect()
disconnect()#
→Promise<void>Disconnects from the voice channel by sending an Opcode 4 payload with a null channel ID.
destroy()
check(connected)
check(connected)#
→voidChecks the connection health. If the connection has failed multiple times consecutively, it triggers a recovery attempt.
Whether the player is currently considered connected by the node.
handleStateUpdate(data)
handleStateUpdate(data)#
→Promise<void>Internal method to handle VOICE_STATE_UPDATE packets from Discord. Updates the session ID and channel ID.
The raw packet data.
handleServerUpdate(data)
Internal method to handle VOICE_SERVER_UPDATE packets from Discord. Updates the token and endpoint.
The raw packet data.