Voice
player.voices holds one VoiceState per connected guild. A voice connection requires two Discord gateway events to establish — Discolink handles them once you forward their raw payloads.
Forwarding payloads
Section titled “Forwarding payloads”When your bot joins a voice channel, Discord sends VOICE_STATE_UPDATE and VOICE_SERVER_UPDATE. Discolink waits for both, then makes a request to Lavalink to register the player. Forward all raw dispatches — Discolink filters for them internally:
// 'rawWS' for erisclient.on("raw", (payload) => player.voices.handleDispatch(payload));handleDispatch processes three event types:
VOICE_STATE_UPDATE— captures the bot’s session ID and channelVOICE_SERVER_UPDATE— captures the endpoint and token, then completes the connectionREADY— triggersplayer.init()automatically whenautoInit: true
Connecting
Section titled “Connecting”const voice = await player.voices.connect(guildId, voiceChannelId);
// With options (only applied when creating a new connection)await player.voices.connect(guildId, voiceChannelId, { node: "eu-west", // pin to a specific node volume: 80, // initial volume for the queue (0–1000) filters: { timescale: { speed: 1.1 } }, // initial filters context: { textChannelId }, // initial queue context});If a connection to the same guild and channel is already in progress, connect() returns the existing promise rather than starting a new one. If the bot is already connected to that channel and the connection is live, it returns the existing VoiceState immediately.
connect() times out after voiceTimeout milliseconds (default 10_000 / 10s) if the gateway events don’t arrive.
Why a connection might fail
Section titled “Why a connection might fail”forwardVoiceUpdatenot wired up — the bot never sends the voice state update to Discord, so the gateway never sends the required events back.handleDispatchnot wired up —VOICE_STATE_UPDATE/VOICE_SERVER_UPDATEare never forwarded to discolink, so it never receives the data it needs to complete the connection.- Missing
GuildVoiceStatesintent — Discord won’t sendVOICE_STATE_UPDATEwithout it, which means the session ID is never captured. - Missing channel permissions — the bot needs
Connect(andSpeakto produce audio) on the target channel. - Voice channel is full — easy to miss: when the channel has hit its user limit, Discord does not send any voice updates, so the connection times out. The bot needs the
Move Memberspermission to bypass the limit and receive both events.
Node selection for voice
Section titled “Node selection for voice”When a new connection is established or a node change is requested without specifying a node, Discolink picks the best node for the voice region. It uses VoiceRegion.getRelevantNode(), which:
- Runs
NodeManager.relevant()to get ready nodes sorted by their metrics - Sorts them by their voice ping in that region — the median ping plus spike penalty
- Returns the first result
The spike penalty is controlled by the voicePenalty player option (default 0, clamped to [0, 1]). With the default, selection uses the median alone; higher values push nodes with erratic latency down the list.
Access the region through player.voices.regions using the voice state’s regionId:
const region = player.voices.regions.get(voice.regionId)!;
const node = region.getRelevantNode("us-east"); // skip us-eastNode ping entries can also be cleared:
region.forgetNode("us-east"); // remove a node's ping statsregion.forgetAllNodes(); // clear all node ping stats for this regionPing data is collected from queueUpdate ticks — each tick carries the voice WebSocket latency from Lavalink. Samples are kept for the region’s windowSize (the regionWindow player option, 300_000 ms / 5 min by default). Nodes with no entry for the region sort first so they get tried; nodes with stale data score -1, and nodes with fewer than four samples are ranked by their median.
The region also exposes its ping data directly:
region.windowSize; // sample window in ms (regionWindow option)region.hasNode("us-east"); // whether this region has data for a noderegion.inSync(); // whether all ready nodes have dataregion.getMedianPing("us-east"); // median ping in ms, -1 if insufficientregion.getAveragePing("us-east"); // average ping in ms, -1 if insufficientConnection state
Section titled “Connection state”const voice = player.voices.get(guildId)!;
voice.connected; // true when Lavalink reports the player connectedvoice.reconnecting; // true during a voice reconnectvoice.disconnected; // true when not connected and not reconnectingvoice.changingNode; // true while changeNode() is in progressvoice.destroyed; // true if this instance is no longer in VoiceManagervoice.unusable; // true if destroyed or its queue is being destroyed
voice.channelId; // current voice channel IDvoice.joined; // true when the bot is in a voice channelvoice.regionId; // voice region extracted from the endpoint (e.g. 'us-east')voice.ping; // voice WebSocket latency in ms, sourced from Lavalink player statevoice.node; // the Node this connection is on
voice.selfDeaf; // whether the bot has deafened itselfvoice.selfMute; // whether the bot has muted itselfvoice.serverDeaf; // whether the guild has deafened the botvoice.serverMute; // whether the guild has muted the botvoice.suppressed; // whether the bot is suppressed (stage channels)Automatic voice reconnection
Section titled “Automatic voice reconnection”When a voice connection is severed, Discolink emits voiceClose after having received the corresponding event from the connection’s node and checks the close code. For recoverable codes (4004, 4006, 4011) with voiceReconnect enabled, it calls voice.reconnect(). voiceDisconnect fires only when that reconnect attempt fails — a non-recoverable code, or voiceReconnect: false does not emit it.
Disconnecting and destroying
Section titled “Disconnecting and destroying”// Leave the channel but keep the VoiceState and queue aliveawait player.voices.disconnect(guildId);
// Tear everything down — destroys the queue and voice connectionawait player.queues.destroy(guildId, "User left the channel");queues.destroy() is the right call when you’re done with a guild — on channel delete, bot kick, or the last user leaving. It removes the Lavalink player, tears down the voice connection, and emits queueDestroy.
disconnect() only leaves the voice channel; it leaves both the VoiceState and its queue fully intact.
You can also call these directly on a VoiceState or Queue instance:
const voice = player.voices.get(guildId)!;await voice.connect(); // connect to the same channelawait voice.connect(otherChannelId); // move to a different channelawait voice.reconnect(); // leave and rejoin the same channelawait voice.disconnect(); // disconnect from the channel
const queue = player.queues.get(guildId)!;await queue.destroy("reason"); // tear down queue and voice connectionMoving to a different node
Section titled “Moving to a different node”await player.voices.get(guildId)!.changeNode("eu-west");
// name is optional, auto-picks the best ready node for the regionawait player.voices.get(guildId)!.changeNode();changeNode() migrates the player to the new node:
- Destroys the player on the old node
- Creates it on the new node with the same state
- Includes and resumes any active track if its source is supported
- Emits
voiceChangewith the previous node and whether playback was active
If changeNode() is already in progress for this voice state, the call returns the existing promise.
With relocateQueues: true (the default), this happens automatically when a node closes or disconnects. The relocation algorithm distributes queues across available nodes proportionally by their load scores.
Full API: VoiceState
