discordjs/discord.js · error · RangeError
Unsupported encryption method: ${encryptionMode}
Error message
Unsupported encryption method: ${encryptionMode} What it means
encryptOpusPacket throws this RangeError when the voice gateway has selected an encryption mode (from the `modes` list in the voice server update) that the library's switch statement does not recognize. By design this branch should be unreachable because the mode is negotiated against the supported list, so it indicates a mismatch between what the gateway advertised and what this library version supports. It almost always means the library is outdated or the gateway is behaving unexpectedly.
Source
Thrown at packages/voice/src/networking/Networking.ts:810
encrypted = Buffer.concat([cipher.update(packet), cipher.final(), cipher.getAuthTag()]);
return [encrypted, noncePadding];
}
case 'aead_xchacha20_poly1305_rtpsize': {
encrypted = secretbox.methods.crypto_aead_xchacha20poly1305_ietf_encrypt(
packet,
additionalData,
connectionData.nonceBuffer,
secretKey,
);
return [encrypted, noncePadding];
}
default: {
// This should never happen. Our encryption mode is chosen from a list given to us by the gateway and checked with the ones we support.
throw new RangeError(`Unsupported encryption method: ${encryptionMode}`);
}
}
}
}
View on GitHub (pinned to a81ed8a306)
Solutions
- Update @discordjs/voice (and discord.js if applicable) to the latest version so the switch supports the encryption mode your gateway negotiated.
- Log the negotiated encryptionMode from the voice server update to identify which unsupported mode was selected.
- If you intentionally control the modes list (e.g. in a mock), restrict it to supported values: aead_xchacha20_poly1305_rtpsize, xsalsa20_poly1305_lite, xsalsa20_poly1305_suffix, xsalsa20_poly1305.
- Report the issue to the library maintainers if the gateway advertises a legitimate mode the latest version rejects.
Example fix
// before
const connection = joinVoiceChannel({ ... }); // library v0.13 negotiating aead_xchacha20_poly1305_rtpsize fails
// after
// npm i @discordjs/voice@latest
// (upgrade ensures the new mode is handled in encryptOpusPacket's switch) Defensive patterns
Strategy: try-catch
Validate before calling
// After receiving the voice server update, before playing:
const SUPPORTED = ['aead_xchacha20_poly1305_rtpsize', 'xsalsa20_poly1305_lite', 'xsalsa20_poly1305_suffix', 'xsalsa20_poly1305'];
if (!SUPPORTED.includes(encryptionMode)) throw new Error(`Library does not support negotiated mode: ${encryptionMode} — update @discordjs/voice`); Type guard
function isSupportedEncryptionMode(m: string): m is 'aead_xchacha20_poly1305_rtpsize' | 'xsalsa20_poly1305_lite' | 'xsalsa20_poly1305_suffix' | 'xsalsa20_poly1305' {
return ['aead_xchacha20_poly1305_rtpsize', 'xsalsa20_poly1305_lite', 'xsalsa20_poly1305_suffix', 'xsalsa20_poly1305'].includes(m);
} Try / catch
try {
connection.playResource(resource);
} catch (e) {
if (e instanceof RangeError && e.message.startsWith('Unsupported encryption method')) {
connection.destroy(); // renegotiate / upgrade library before retrying
} else throw e;
} Prevention
- Keep @discordjs/voice updated — new Discord encryption modes land there first.
- Pin and test against the mode list your bot deployment actually receives.
- Call generateDependencyReport() when diagnosing voice issues to see library and crypto versions.
- Never hardcode a modes list in gateway mocks without keeping it in sync with supported modes.
When it happens
Trigger: Calling VoiceConnection.playOpus/createAudioPacket while the negotiated encryptionMode is a string not handled by the switch in encryptOpusPacket (e.g. a new mode like aead_xchacha20_poly1305_rtpsize supported by the gateway but not by an old library version, or a corrupted mode value from the gateway).
Common situations: Running an outdated @discordjs/voice version after Discord introduced a new encryption mode; a malicious/spoofed gateway returning a bogus mode; manual mocking of gateway signals in tests with an unknown mode string.
Related errors
- Unsupported decryption method: ${mode}
- No compatible encryption modes. Available include: ${options
- Invalid extension provided: ${extension} Must be one of: ${a
- Invalid size provided: ${size} Must be one of: ${ALLOWED_SIZ
- Cannot destroy VoiceConnection - it has already been destroy
AI-assisted analysis of discordjs/discord.js@a81ed8a306 (2026-08-30).
Data as JSON: /api/errors/e32abc9d2b5cf84d.
Report an issue: GitHub.