discordjs/discord.js · error · Error

Malformed IP address

Error message

Malformed IP address

What it means

parseLocalPacket parses the UDP IP-discovery response that Discord sends so the client can learn its local IP/port for voice. It extracts the IP from bytes 8..first-null of the 74-byte packet and validates it with node:net's isIPv4; if the extracted bytes are not a valid IPv4 address it throws this Error. This means the discovery response was malformed or the packet framing changed.

Source

Thrown at packages/voice/src/networking/VoiceUDPSocket.ts:26

 * for Discord.
 */
export interface SocketConfig {
	ip: string;
	port: number;
}

/**
 * Parses the response from Discord to aid with local IP discovery.
 *
 * @param message - The received message
 */
export function parseLocalPacket(message: Buffer): SocketConfig {
	const packet = Buffer.from(message);

	const ip = packet.subarray(8, packet.indexOf(0, 8)).toString('utf8');

	if (!isIPv4(ip)) {
		throw new Error('Malformed IP address');
	}

	const port = packet.readUInt16BE(packet.length - 2);

	return { ip, port };
}

/**
 * The interval in milliseconds at which keep alive datagrams are sent.
 */
const KEEP_ALIVE_INTERVAL = 5e3;

/**
 * The maximum value of the keep alive counter.
 */
const MAX_COUNTER_VALUE = 2 ** 32 - 1;

export interface VoiceUDPSocket extends EventEmitter {

View on GitHub (pinned to a81ed8a306)

Solutions

  1. Retry the voice connection (destroy and rejoin the voice channel) — transient UDP corruption is the most common cause.
  2. Check VPN, proxy, and firewall setups that intercept or rewrite UDP packets and try a direct connection.
  3. Verify the UDP socket is actually talking to the gateway-provided IP (see VoiceUDPSocket) and not an interception layer.
  4. Update @discordjs/voice in case of a protocol/framing change; report if it persists.

Example fix

// before
await connection.connect(); // may throw 'Malformed IP address' behind a VPN
// after
try {
  await connection.connect();
} catch (e) {
  connection.destroy(); // then rejoin to retry the UDP discovery handshake
}
Defensive patterns

Strategy: retry

Validate before calling

// Validate the discovery response yourself if you handle raw UDP:
const net = require('node:net');
if (!net.isIPv4(ip)) { /* rejoin / retry instead of proceeding */ }

Type guard

function isValidLocalPacket(cfg: { ip: string; port: number }): boolean {
  return net.isIPv4(cfg.ip) && cfg.port > 0 && cfg.port <= 65535;
}

Try / catch

try {
  await connection.connect();
} catch (e) {
  if (e.message === 'Malformed IP address') {
    connection.destroy();
    await joinVoiceChannel(channelConfig); // retry discovery once or twice
  } else throw e;
}

Prevention

When it happens

Trigger: Receiving a UDP discovery (SELECT_PROTOCOL READY) response whose bytes 8..N do not form a valid IPv4 string — e.g. a truncated packet, a response from a non-Discord/intercepting server, or networking middleware rewriting the payload.

Common situations: Running voice traffic through a VPN/proxy/corporate firewall that mangles UDP; custom Discord API mocks returning a wrongly shaped discovery payload; rare Discord-side protocol changes; packet corruption on flaky networks.

Understand the failure class

Related errors


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