discordjs/discord.js · error · Error

Session not available

Error message

Session not available

What it means

getVerificationCode() asks the connection's DAVE protocol session for an E2EE verification code, but throws 'Session not available' when the networking stack is not in the Ready state with an active DAVE session.

Source

Thrown at packages/voice/src/VoiceConnection.ts:762

		return undefined;
	}

	/**
	 * Gets the verification code for a user in the session.
	 *
	 * @throws Will throw if end-to-end encryption is not on or if the user id provided is not in the session.
	 */
	public async getVerificationCode(userId: string): Promise<string> {
		if (
			this.state.status === VoiceConnectionStatus.Ready &&
			this.state.networking.state.code === NetworkingStatusCode.Ready &&
			this.state.networking.state.dave
		) {
			return this.state.networking.state.dave.getVerificationCode(userId);
		}

		throw new Error('Session not available');
	}

	/**
	 * Called when a subscription of this voice connection to an audio player is removed.
	 *
	 * @param subscription - The removed subscription
	 */
	protected onSubscriptionRemoved(subscription: PlayerSubscription) {
		if (this.state.status !== VoiceConnectionStatus.Destroyed && this.state.subscription === subscription) {
			this.state = {
				...this.state,
				subscription: undefined,
			};
		}
	}
}

/**

View on GitHub (pinned to a81ed8a306)

Solutions

  1. Wait for VoiceConnectionStatus.Ready (or the appropriate signage/networking ready event) before calling getVerificationCode()
  2. Check connection.state.status and nested networking state before invoking
  3. Re-fetch after reconnection completes rather than caching a call made during setup

Example fix

// before
const code = connection.getVerificationCode(userId);
// after
if (connection.state.status === VoiceConnectionStatus.Ready) {
  const code = connection.getVerificationCode(userId);
} else {
  connection.once(VoiceConnectionStatus.Ready, () => connection.getVerificationCode(userId));
}
Defensive patterns

Strategy: try-catch

Validate before calling

import { VoiceConnectionStatus } from '@discordjs/voice';
function canGetCode(connection: VoiceConnection): boolean {
  return connection.state.status === VoiceConnectionStatus.Ready;
}

Type guard

function isReadyForVerification(c: VoiceConnection): boolean {
  return c.state.status === VoiceConnectionStatus.Ready;
}

Try / catch

try {
  const code = connection.getVerificationCode(userId);
} catch (err) {
  if (err.message === 'Session not available') {
    // wait for Ready and retry
    connection.once(VoiceConnectionStatus.Ready, () => connection.getVerificationCode(userId));
  } else throw err;
}

Prevention

When it happens

Trigger: Calling connection.getVerificationCode(userId) before the voice connection is fully ready, after a reconnect/resignaling, or on a connection where DAVE (encryption) was never established.

Common situations: Querying the code immediately after joinVoiceChannel() before VoiceConnectionStatus.Ready, calling during a voice server switch, or when the wire uses non-DAVE modes.

Related errors


AI-assisted analysis of discordjs/discord.js@a81ed8a306 (2026-08-30). Data as JSON: /api/errors/b21e80ebe9149bdb. Report an issue: GitHub.