discordjs/discord.js · error · Error
Session not available
Error message
Session not available
What it means
DAVESession.getVerificationCode() throws when this.session is null — i.e. the underlying MLS session has not been initialized yet (or failed to initialize). A verification code can only be obtained from an active session.
Source
Thrown at packages/voice/src/networking/DAVESession.ts:152
/**
* The current voice privacy code of the session. Will be `null` if there is no session.
*/
public get voicePrivacyCode(): string | null {
if (this.protocolVersion === 0 || !this.session?.voicePrivacyCode) {
return null;
}
return this.session.voicePrivacyCode;
}
/**
* Gets the verification code for a user in the session.
*
* @throws Will throw if there is not an active session or the user id provided is invalid or not in the session.
*/
public async getVerificationCode(userId: string): Promise<string> {
if (!this.session) throw new Error('Session not available');
return this.session.getVerificationCode(userId);
}
/**
* Re-initializes (or initializes) the underlying session.
*/
public reinit() {
if (this.protocolVersion > 0) {
if (this.session) {
this.session.reinit(this.protocolVersion, this.userId, this.channelId);
this.emit('debug', `Session reinitialized for protocol version ${this.protocolVersion}`);
} else {
this.session = new Davey.DAVESession(this.protocolVersion, this.userId, this.channelId);
this.emit('debug', `Session initialized for protocol version ${this.protocolVersion}`);
}
this.emit('keyPackage', this.session!.getSerializedKeyPackage());
} else if (this.session) {View on GitHub (pinned to a81ed8a306)
Solutions
- Wait for the session 'ready'/protocolReady event before calling getVerificationCode
- Verify the optional dependency @snazzah/davey is installed at a compatible version
- Reinitialize the session (reinit()) if it failed, then retry
- Check userId validity and that the user is in the session once initialized
Example fix
// before
daveSession.getVerificationCode(userId); // may throw
// after
if (daveSessionReady) {
await daveSession.getVerificationCode(userId);
} Defensive patterns
Strategy: retry
Validate before calling
function canGetCode(session) { return typeof (session as any).session !== 'undefined' && (session as any).session !== null; }
if (!canGetCode(dave)) await waitForSessionReady(dave); Type guard
function hasActiveSession(s: { session?: unknown }): boolean { return s.session != null; } Try / catch
try { code = await dave.getVerificationCode(userId); } catch (e) { if (e.message === 'Session not available') { await onceReady(dave); code = await dave.getVerificationCode(userId); } else throw e; } Prevention
- Gate DAVE calls on the session ready/protocolReady event
- Verify @snazzah/davey is installed and version-compatible
- Handle reinit lifecycle events before issuing session calls
- Validate userId is a participant before requesting codes
When it happens
Trigger: Calling getVerificationCode(userId) before the DAVE session is ready — before the initial protocolReady/reinit completes, or after the session was torn down / failed to initialize.
Common situations: Requesting verification codes immediately after joining a voice channel before DAVESession signals readiness; session initialization failed (missing/wrong @snazzah/davey dependency version); session reinitialization in progress.
Related errors
- No session available
- Cannot destroy VoiceConnection - it has already been destroy
- ClientNotReady
- Session not available
- No compatible encryption modes. Available include: ${options
AI-assisted analysis of discordjs/discord.js@a81ed8a306 (2026-08-30).
Data as JSON: /api/errors/776f81a70641ab05.
Report an issue: GitHub.