discordjs/discord.js · error · TypeError

fetchGatewayInformation is required

Error message

fetchGatewayInformation is required

What it means

The WebSocketManager constructor requires fetchGatewayInformation to be a function because the manager cannot fetch Discord gateway metadata (URL, session limits) itself. Passing anything else throws a TypeError immediately at construction time.

Source

Thrown at packages/ws/src/ws/WebSocketManager.ts:270

	/**
	 * Gets the token set for this manager. If no token is set, an error is thrown.
	 * To set the token, use {@link WebSocketManager.setToken} or pass it in the options.
	 *
	 * @remarks
	 * This getter is mostly used to pass the token to the sharding strategy internally, there's not much reason to use it.
	 */
	public get token(): string {
		if (!this.#token) {
			throw new Error('Token has not been set');
		}

		return this.#token;
	}

	public constructor(options: CreateWebSocketManagerOptions) {
		if (typeof options.fetchGatewayInformation !== 'function') {
			throw new TypeError('fetchGatewayInformation is required');
		}

		super();
		this.options = {
			...DefaultWebSocketManagerOptions,
			...options,
		};
		this.strategy = this.options.buildStrategy(this);
		this.#token = options.token ?? null;
	}

	/**
	 * Fetches the gateway information from Discord - or returns it from cache if available
	 *
	 * @param force - Whether to ignore the cache and force a fresh fetch
	 */
	public async fetchGatewayInformation(force = false) {
		if (this.gatewayInformation) {

View on GitHub (pinned to a81ed8a306)

Solutions

  1. Provide a fetchGatewayInformation function (typically rest.get(Routes.gatewayBot())) in the options object
  2. Check the options object is fully constructed before instantiation
  3. Spread order issue: ensure your overrides don't overwrite the function with undefined

Example fix

// before
const manager = new WebSocketManager({ token, rest });
// after
const manager = new WebSocketManager({
  token,
  rest,
  fetchGatewayInformation: () => rest.get(Routes.gatewayBot()),
});
Defensive patterns

Strategy: validation

Validate before calling

if (typeof options.fetchGatewayInformation !== 'function') {
  throw new TypeError('fetchGatewayInformation must be provided to WebSocketManager');
}
const manager = new WebSocketManager(options);

Type guard

function isValidManagerOptions(o: unknown): o is CreateWebSocketManagerOptions {
  return typeof o === 'object' && o !== null && typeof (o as CreateWebSocketManagerOptions).fetchGatewayInformation === 'function';
}

Try / catch

try {
  const manager = new WebSocketManager(options);
} catch (e) {
  if (e instanceof TypeError) {
    console.error('Manager options incomplete:', e.message);
  } else throw e;
}

Prevention

When it happens

Trigger: new WebSocketManager({...}) called with options.fetchGatewayInformation missing, undefined, or set to a non-function value (string, object, etc.).

Common situations: Copy-pasting options from a REST-only setup; building options dynamically and the fetch function is not spread in; using an older option shape from a previous library version.

Related errors


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