{"record":{"id":"53afd9a00c6974ba","repo":"discordjs/discord.js","slug":"fetchgatewayinformation-is-required","errorCode":null,"errorMessage":"fetchGatewayInformation is required","messagePattern":"fetchGatewayInformation is required","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/ws/src/ws/WebSocketManager.ts","lineNumber":270,"sourceCode":"\n\t/**\n\t * Gets the token set for this manager. If no token is set, an error is thrown.\n\t * To set the token, use {@link WebSocketManager.setToken} or pass it in the options.\n\t *\n\t * @remarks\n\t * This getter is mostly used to pass the token to the sharding strategy internally, there's not much reason to use it.\n\t */\n\tpublic get token(): string {\n\t\tif (!this.#token) {\n\t\t\tthrow new Error('Token has not been set');\n\t\t}\n\n\t\treturn this.#token;\n\t}\n\n\tpublic constructor(options: CreateWebSocketManagerOptions) {\n\t\tif (typeof options.fetchGatewayInformation !== 'function') {\n\t\t\tthrow new TypeError('fetchGatewayInformation is required');\n\t\t}\n\n\t\tsuper();\n\t\tthis.options = {\n\t\t\t...DefaultWebSocketManagerOptions,\n\t\t\t...options,\n\t\t};\n\t\tthis.strategy = this.options.buildStrategy(this);\n\t\tthis.#token = options.token ?? null;\n\t}\n\n\t/**\n\t * Fetches the gateway information from Discord - or returns it from cache if available\n\t *\n\t * @param force - Whether to ignore the cache and force a fresh fetch\n\t */\n\tpublic async fetchGatewayInformation(force = false) {\n\t\tif (this.gatewayInformation) {","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/discordjs/discord.js/blob/a81ed8a306d37fdc746e26a634b6a42164ba2c8c/packages/ws/src/ws/WebSocketManager.ts#L252-L288","documentation":"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.","triggerScenarios":"new WebSocketManager({...}) called with options.fetchGatewayInformation missing, undefined, or set to a non-function value (string, object, etc.).","commonSituations":"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.","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"],"exampleFix":"// before\nconst manager = new WebSocketManager({ token, rest });\n// after\nconst manager = new WebSocketManager({\n  token,\n  rest,\n  fetchGatewayInformation: () => rest.get(Routes.gatewayBot()),\n});","handlingStrategy":"validation","validationCode":"if (typeof options.fetchGatewayInformation !== 'function') {\n  throw new TypeError('fetchGatewayInformation must be provided to WebSocketManager');\n}\nconst manager = new WebSocketManager(options);","typeGuard":"function isValidManagerOptions(o: unknown): o is CreateWebSocketManagerOptions {\n  return typeof o === 'object' && o !== null && typeof (o as CreateWebSocketManagerOptions).fetchGatewayInformation === 'function';\n}","tryCatchPattern":"try {\n  const manager = new WebSocketManager(options);\n} catch (e) {\n  if (e instanceof TypeError) {\n    console.error('Manager options incomplete:', e.message);\n  } else throw e;\n}","preventionTips":["Always include fetchGatewayInformation: () => rest.get(Routes.gatewayBot()) in options","Type the options object as CreateWebSocketManagerOptions so TypeScript catches missing fields at compile time"],"tags":["typescript","configuration","constructor"],"backgroundTag":"missing-required-option","analyzedSha":"a81ed8a306d37fdc746e26a634b6a42164ba2c8c","analyzedAt":"2026-08-30T04:07:22.193Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}