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
- Provide a fetchGatewayInformation function (typically rest.get(Routes.gatewayBot())) in the options object
- Check the options object is fully constructed before instantiation
- 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
- Always include fetchGatewayInformation: () => rest.get(Routes.gatewayBot()) in options
- Type the options object as CreateWebSocketManagerOptions so TypeScript catches missing fields at compile time
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
- Package ${packageName} not releaseable
- The --tag option can only be used with --dev
- ClientMissingIntents
- Cannot set an interval greater than 4 hours
- Expected token to be set for this request, but none was pres
AI-assisted analysis of discordjs/discord.js@a81ed8a306 (2026-08-30).
Data as JSON: /api/errors/53afd9a00c6974ba.
Report an issue: GitHub.