{"record":{"id":"2e33fdfa9c268a74","repo":"discordjs/discord.js","slug":"invalidelement","errorCode":"InvalidElement","errorMessage":"Supplied ${type} ${name} includes an invalid element: ${elem}","messagePattern":"Supplied (.+?) (.+?) includes an invalid element: (.+?)","errorType":"error_code","errorClass":"DiscordjsTypeError","httpStatus":null,"severity":"error","filePath":"packages/discord.js/src/client/Client.js","lineNumber":760,"sourceCode":"      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    }\n\n    if (options.guild) {\n      const guildId = this.guilds.resolveId(options.guild);\n      if (!guildId) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'options.guild', 'GuildResolvable');\n      query.set('guild_id', guildId);\n    }","sourceCodeStart":742,"sourceCodeEnd":778,"githubUrl":"https://github.com/discordjs/discord.js/blob/a81ed8a306d37fdc746e26a634b6a42164ba2c8c/packages/discord.js/src/client/Client.js#L742-L778","documentation":"InvalidElement is thrown when a scope inside the scopes array is not a recognized OAuth2Scopes value. generateInvite() validates every element against Object.values(OAuth2Scopes) and reports the first offending element in the message, so malformed scopes never reach the generated URL.","triggerScenarios":"scopes: ['bots'], scopes: ['BOT'], scopes: ['application.commands'] — strings not matching any OAuth2Scopes enum member, including wrong casing or hyphenated variants.","commonSituations":"Hand-typing scope strings from memory or from outdated documentation; mixing in custom scopes; case errors ('Bot' vs 'bot'); migrating from v11-era permission strings.","solutions":["Use only values from the imported OAuth2Scopes enum, e.g. [OAuth2Scopes.Bot, OAuth2Scopes.ApplicationsCommands]","Check casing and spelling against the OAuth2Scopes enum definition","Filter/validate the scopes array before calling: scopes.every(s => Object.values(OAuth2Scopes).includes(s))"],"exampleFix":"// before\nconst link = client.generateInvite({ scopes: ['bot', 'application.commands'] });\n// after\nconst { OAuth2Scopes } = require('discord.js');\nconst link = client.generateInvite({ scopes: [OAuth2Scopes.Bot, OAuth2Scopes.ApplicationsCommands] });","handlingStrategy":"validation","validationCode":"const valid = Object.values(OAuth2Scopes);\nconst bad = scopes.filter((s) => !valid.includes(s));\nif (bad.length) throw new Error(`Unknown scopes: ${bad.join(', ')}`);","typeGuard":"const allScopesValid = (scopes) =>\n  Array.isArray(scopes) && scopes.every((s) => Object.values(OAuth2Scopes).includes(s));","tryCatchPattern":"try {\n  const link = client.generateInvite({ scopes });\n} catch (err) {\n  if (err.code === 'InvalidElement') console.error(`Bad scope in list: ${err.message}`);\n  else throw err;\n}","preventionTips":["Source every scope from the OAuth2Scopes enum","Never type scope strings by hand or from memory","Validate user/config-supplied scope lists against the enum before use","Use TypeScript with OAuth2Scopes[] typing for compile-time safety"],"tags":["discord-js","oauth2","invalid-element","enum-validation"],"backgroundTag":"invalid-argument-type","analyzedSha":"a81ed8a306d37fdc746e26a634b6a42164ba2c8c","analyzedAt":"2026-08-30T04:07:22.193Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}