{"record":{"id":"b21e80ebe9149bdb","repo":"discordjs/discord.js","slug":"session-not-available","errorCode":null,"errorMessage":"Session not available","messagePattern":"Session not available","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/voice/src/VoiceConnection.ts","lineNumber":762,"sourceCode":"\n\t\treturn undefined;\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 end-to-end encryption is not on or if the user id provided is not in the session.\n\t */\n\tpublic async getVerificationCode(userId: string): Promise<string> {\n\t\tif (\n\t\t\tthis.state.status === VoiceConnectionStatus.Ready &&\n\t\t\tthis.state.networking.state.code === NetworkingStatusCode.Ready &&\n\t\t\tthis.state.networking.state.dave\n\t\t) {\n\t\t\treturn this.state.networking.state.dave.getVerificationCode(userId);\n\t\t}\n\n\t\tthrow new Error('Session not available');\n\t}\n\n\t/**\n\t * Called when a subscription of this voice connection to an audio player is removed.\n\t *\n\t * @param subscription - The removed subscription\n\t */\n\tprotected onSubscriptionRemoved(subscription: PlayerSubscription) {\n\t\tif (this.state.status !== VoiceConnectionStatus.Destroyed && this.state.subscription === subscription) {\n\t\t\tthis.state = {\n\t\t\t\t...this.state,\n\t\t\t\tsubscription: undefined,\n\t\t\t};\n\t\t}\n\t}\n}\n\n/**","sourceCodeStart":744,"sourceCodeEnd":780,"githubUrl":"https://github.com/discordjs/discord.js/blob/a81ed8a306d37fdc746e26a634b6a42164ba2c8c/packages/voice/src/VoiceConnection.ts#L744-L780","documentation":"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.","triggerScenarios":"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.","commonSituations":"Querying the code immediately after joinVoiceChannel() before VoiceConnectionStatus.Ready, calling during a voice server switch, or when the wire uses non-DAVE modes.","solutions":["Wait for VoiceConnectionStatus.Ready (or the appropriate signage/networking ready event) before calling getVerificationCode()","Check connection.state.status and nested networking state before invoking","Re-fetch after reconnection completes rather than caching a call made during setup"],"exampleFix":"// before\nconst code = connection.getVerificationCode(userId);\n// after\nif (connection.state.status === VoiceConnectionStatus.Ready) {\n  const code = connection.getVerificationCode(userId);\n} else {\n  connection.once(VoiceConnectionStatus.Ready, () => connection.getVerificationCode(userId));\n}","handlingStrategy":"try-catch","validationCode":"import { VoiceConnectionStatus } from '@discordjs/voice';\nfunction canGetCode(connection: VoiceConnection): boolean {\n  return connection.state.status === VoiceConnectionStatus.Ready;\n}","typeGuard":"function isReadyForVerification(c: VoiceConnection): boolean {\n  return c.state.status === VoiceConnectionStatus.Ready;\n}","tryCatchPattern":"try {\n  const code = connection.getVerificationCode(userId);\n} catch (err) {\n  if (err.message === 'Session not available') {\n    // wait for Ready and retry\n    connection.once(VoiceConnectionStatus.Ready, () => connection.getVerificationCode(userId));\n  } else throw err;\n}","preventionTips":["Only request verification codes after the connection reaches Ready","Re-request after every reconnect or voice server switch","Do not cache codes across session changes"],"tags":["voice","e2ee","state"],"backgroundTag":"session-not-ready","analyzedSha":"a81ed8a306d37fdc746e26a634b6a42164ba2c8c","analyzedAt":"2026-08-30T04:07:22.193Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}