{"record":{"id":"776f81a70641ab05","repo":"discordjs/discord.js","slug":"session-not-available-776f81","errorCode":null,"errorMessage":"Session not available","messagePattern":"Session not available","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/voice/src/networking/DAVESession.ts","lineNumber":152,"sourceCode":"\n\t/**\n\t * The current voice privacy code of the session. Will be `null` if there is no session.\n\t */\n\tpublic get voicePrivacyCode(): string | null {\n\t\tif (this.protocolVersion === 0 || !this.session?.voicePrivacyCode) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn this.session.voicePrivacyCode;\n\t}\n\n\t/**\n\t * Gets the verification code for a user in the session.\n\t *\n\t * @throws Will throw if there is not an active session or the user id provided is invalid or not in the session.\n\t */\n\tpublic async getVerificationCode(userId: string): Promise<string> {\n\t\tif (!this.session) throw new Error('Session not available');\n\t\treturn this.session.getVerificationCode(userId);\n\t}\n\n\t/**\n\t * Re-initializes (or initializes) the underlying session.\n\t */\n\tpublic reinit() {\n\t\tif (this.protocolVersion > 0) {\n\t\t\tif (this.session) {\n\t\t\t\tthis.session.reinit(this.protocolVersion, this.userId, this.channelId);\n\t\t\t\tthis.emit('debug', `Session reinitialized for protocol version ${this.protocolVersion}`);\n\t\t\t} else {\n\t\t\t\tthis.session = new Davey.DAVESession(this.protocolVersion, this.userId, this.channelId);\n\t\t\t\tthis.emit('debug', `Session initialized for protocol version ${this.protocolVersion}`);\n\t\t\t}\n\n\t\t\tthis.emit('keyPackage', this.session!.getSerializedKeyPackage());\n\t\t} else if (this.session) {","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/discordjs/discord.js/blob/a81ed8a306d37fdc746e26a634b6a42164ba2c8c/packages/voice/src/networking/DAVESession.ts#L134-L170","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\ndaveSession.getVerificationCode(userId); // may throw\n// after\nif (daveSessionReady) {\n  await daveSession.getVerificationCode(userId);\n}","handlingStrategy":"retry","validationCode":"function canGetCode(session) { return typeof (session as any).session !== 'undefined' && (session as any).session !== null; }\nif (!canGetCode(dave)) await waitForSessionReady(dave);","typeGuard":"function hasActiveSession(s: { session?: unknown }): boolean { return s.session != null; }","tryCatchPattern":"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; }","preventionTips":["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"],"tags":["voice","mls","dave","lifecycle"],"backgroundTag":"session-not-initialized","analyzedSha":"a81ed8a306d37fdc746e26a634b6a42164ba2c8c","analyzedAt":"2026-08-30T04:07:22.193Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}