{"record":{"id":"448cb2b79c2ffd68","repo":"discordjs/discord.js","slug":"a-client-id-must-be-provided-to-login","errorCode":null,"errorMessage":"A client id must be provided to login","messagePattern":"A client id must be provided to login","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/rpc/src/client.ts","lineNumber":229,"sourceCode":"\n\t\treturn promise;\n\t}\n\n\t/**\n\t * Performs authentication flow. Automatically calls Client#connect if needed.\n\t *\n\t * @example\n\t * logging in with a client id and secret\n\t * ```ts\n\t * client.login({ clientId: '1234567', clientSecret: 'abcdef123' });\n\t * ```\n\t */\n\tpublic async login(\n\t\t{ clientId, clientSecret, accessToken }: RPCLoginOptions,\n\t\toptions?: RequestOptions,\n\t): Promise<RPCClient> {\n\t\tif (!clientId) {\n\t\t\tthrow new Error('A client id must be provided to login');\n\t\t}\n\n\t\tthis.clientId = clientId;\n\n\t\tawait this.connect(options);\n\n\t\tif (!this.options.scopes) {\n\t\t\tthis.emit(Events.ApplicationReady);\n\t\t\treturn this;\n\t\t}\n\n\t\tif (accessToken) {\n\t\t\treturn this.authenticate(accessToken, options);\n\t\t}\n\n\t\tif (!clientSecret) {\n\t\t\tthrow new Error('A client secret must be provided for authorization if scopes are included');\n\t\t}","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/discordjs/discord.js/blob/a81ed8a306d37fdc746e26a634b6a42164ba2c8c/packages/rpc/src/client.ts#L211-L247","documentation":"The RPC client's login() throws this plain Error when RPCLoginOptions.clientId is missing/empty, before any connection is attempted. The RPC (rich presence) transport needs the OAuth application's client id to authenticate the socket, so login() validates it upfront at client.ts:229.","triggerScenarios":"Calling client.login({}) or client.login({ clientSecret, accessToken }) without clientId; passing clientId from an unset environment variable (process.env.DISCORD_CLIENT_ID === undefined); typo in the option key (client_id or applicationId instead of clientId).","commonSituations":"Rich-presence scripts run without a .env file loaded (dotenv not required first); copying example code that reads env vars that were never set; hardcoding secret but forgetting the public client id; migrating from another RPC library whose option name differs.","solutions":["Pass clientId explicitly: client.login({ clientId: 'your-application-id' }) using the application's ID from the Developer Portal.","If loading from env, check it exists before login: if (!process.env.DISCORD_CLIENT_ID) throw ...; and ensure dotenv.config() ran.","Verify the option key is exactly clientId (RPCLoginOptions), not client_id or applicationId.","If you already have an accessToken from a prior OAuth flow, you still must supply clientId alongside it."],"exampleFix":"// before\nawait client.login({ clientSecret: process.env.CLIENT_SECRET });\n// after\nif (!process.env.DISCORD_CLIENT_ID) throw new Error('DISCORD_CLIENT_ID is not set');\nawait client.login({\n  clientId: process.env.DISCORD_CLIENT_ID,\n  clientSecret: process.env.CLIENT_SECRET,\n});","handlingStrategy":"validation","validationCode":"function requireClientId(clientId?: string): string {\n  if (typeof clientId !== 'string' || clientId.length === 0) {\n    throw new Error('clientId is required for RPC login');\n  }\n  return clientId;\n}\n// usage\nconst clientId = requireClientId(process.env.DISCORD_CLIENT_ID);","typeGuard":"function hasClientId(o: Partial<RPCLoginOptions>): o is RPCLoginOptions & { clientId: string } {\n  return typeof o.clientId === 'string' && o.clientId.length > 0;\n}","tryCatchPattern":"try {\n  await client.login(options);\n} catch (e) {\n  if (e instanceof Error && e.message === 'A client id must be provided to login') {\n    console.error('Set clientId in RPCLoginOptions (from the Developer Portal application id)');\n  } else throw e;\n}","preventionTips":["Store the application client id in an env var and assert it at startup before login().","Load dotenv before reading env vars in scripts.","Use the exact option key clientId on RPCLoginOptions.","Keep client id and client secret in one config object so one is not forgotten.","Add a config schema check (zod/ajv) for login options in application bootstrap."],"tags":["rpc","configuration","missing-argument","client-id","validation"],"backgroundTag":"missing-required-parameter","analyzedSha":"a81ed8a306d37fdc746e26a634b6a42164ba2c8c","analyzedAt":"2026-08-30T04:07:22.193Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}