{"record":{"id":"89e3dcb1f82828f6","repo":"discordjs/discord.js","slug":"invalidscopeswithpermissions","errorCode":"InvalidScopesWithPermissions","errorMessage":"Permissions cannot be set without the bot scope.","messagePattern":"Permissions cannot be set without the bot scope\\.","errorType":"error_code","errorClass":"DiscordjsTypeError","httpStatus":null,"severity":"error","filePath":"packages/discord.js/src/client/Client.js","lineNumber":754,"sourceCode":"  generateInvite(options = {}) {\n    if (typeof options !== 'object') throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'options', 'object', true);\n    if (!this.application) throw new DiscordjsError(ErrorCodes.ClientNotReady, 'generate an invite link');\n\n    const { scopes } = options;\n    if (scopes === undefined) {\n      throw new DiscordjsTypeError(ErrorCodes.InvalidMissingScopes);\n    }\n\n    if (!Array.isArray(scopes)) {\n      throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'scopes', 'Array of Invite Scopes', true);\n    }\n\n    if (!scopes.some(scope => [OAuth2Scopes.Bot, OAuth2Scopes.ApplicationsCommands].includes(scope))) {\n      throw new DiscordjsTypeError(ErrorCodes.InvalidMissingScopes);\n    }\n\n    if (!scopes.includes(OAuth2Scopes.Bot) && options.permissions) {\n      throw new DiscordjsTypeError(ErrorCodes.InvalidScopesWithPermissions);\n    }\n\n    const validScopes = Object.values(OAuth2Scopes);\n    const invalidScope = scopes.find(scope => !validScopes.includes(scope));\n    if (invalidScope) {\n      throw new DiscordjsTypeError(ErrorCodes.InvalidElement, 'Array', 'scopes', invalidScope);\n    }\n\n    const query = makeURLSearchParams({\n      client_id: this.application.id,\n      scope: scopes.join(' '),\n      disable_guild_select: options.disableGuildSelect,\n    });\n\n    if (options.permissions) {\n      const permissions = PermissionsBitField.resolve(options.permissions);\n      if (permissions) query.set('permissions', permissions.toString());\n    }","sourceCodeStart":736,"sourceCodeEnd":772,"githubUrl":"https://github.com/discordjs/discord.js/blob/a81ed8a306d37fdc746e26a634b6a42164ba2c8c/packages/discord.js/src/client/Client.js#L736-L772","documentation":"DiscordjsTypeError with code InvalidScopesWithPermissions is thrown when options.permissions is supplied but the Bot scope is absent from the scopes array. Permissions only make sense for a bot installation, so specifying them without requesting the bot scope is contradictory and rejected.","triggerScenarios":"client.generateInvite({ scopes: [OAuth2Scopes.ApplicationsCommands], permissions: ['ADMINISTRATOR'] }) — permissions set while scopes omit OAuth2Scopes.Bot.","commonSituations":"Adding application-commands scope and permissions together after removing the bot scope; dynamic scope building where permissions are attached unconditionally.","solutions":["Add OAuth2Scopes.Bot to the scopes array whenever permissions are specified","Remove the permissions option if the invite should not install a bot","Conditionally include permissions only when scopes contain OAuth2Scopes.Bot"],"exampleFix":"// before\nconst link = client.generateInvite({ scopes: [OAuth2Scopes.ApplicationsCommands], permissions: ['ADMINISTRATOR'] });\n// after\nconst link = client.generateInvite({ scopes: [OAuth2Scopes.Bot, OAuth2Scopes.ApplicationsCommands], permissions: ['ADMINISTRATOR'] });","handlingStrategy":"validation","validationCode":"if (opts.permissions && !opts.scopes?.includes(OAuth2Scopes.Bot)) {\n  throw new Error('permissions require the bot scope');\n}","typeGuard":"const permissionsAreValid = (opts) =>\n  !opts.permissions || (Array.isArray(opts.scopes) && opts.scopes.includes(OAuth2Scopes.Bot));","tryCatchPattern":"try {\n  const link = client.generateInvite(opts);\n} catch (err) {\n  if (err.code === 'InvalidScopesWithPermissions') opts.scopes = [...opts.scopes, OAuth2Scopes.Bot];\n  else throw err;\n}","preventionTips":["Couple permissions with the Bot scope in your invite builder","Only set permissions conditionally when the bot scope is present","Document that permissions are bot-installation-only"],"tags":["discord-js","oauth2","permissions","invalid-scopes"],"backgroundTag":"invalid-oauth-scopes","analyzedSha":"a81ed8a306d37fdc746e26a634b6a42164ba2c8c","analyzedAt":"2026-08-30T04:07:22.193Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}