discordjs/discord.js · error · DiscordjsTypeError
InvalidMissingScopes
InvalidMissingScopes
Error message
At least one valid scope must be provided for the invite
What it means
DiscordjsTypeError with code InvalidMissingScopes is thrown when options.scopes is undefined in generateInvite(). Scopes are mandatory because the OAuth2 authorization URL is meaningless without at least one scope; the library requires them explicitly rather than guessing.
Source
Thrown at packages/discord.js/src/client/Client.js:742
* console.log(`Generated application invite link: ${link}`);
* @example
* const link = client.generateInvite({
* permissions: [
* PermissionFlagsBits.SendMessages,
* PermissionFlagsBits.ManageGuild,
* PermissionFlagsBits.MentionEveryone,
* ],
* scopes: [OAuth2Scopes.Bot],
* });
* console.log(`Generated bot invite link: ${link}`);
*/
generateInvite(options = {}) {
if (typeof options !== 'object') throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'options', 'object', true);
if (!this.application) throw new DiscordjsError(ErrorCodes.ClientNotReady, 'generate an invite link');
const { scopes } = options;
if (scopes === undefined) {
throw new DiscordjsTypeError(ErrorCodes.InvalidMissingScopes);
}
if (!Array.isArray(scopes)) {
throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'scopes', 'Array of Invite Scopes', true);
}
if (!scopes.some(scope => [OAuth2Scopes.Bot, OAuth2Scopes.ApplicationsCommands].includes(scope))) {
throw new DiscordjsTypeError(ErrorCodes.InvalidMissingScopes);
}
if (!scopes.includes(OAuth2Scopes.Bot) && options.permissions) {
throw new DiscordjsTypeError(ErrorCodes.InvalidScopesWithPermissions);
}
const validScopes = Object.values(OAuth2Scopes);
const invalidScope = scopes.find(scope => !validScopes.includes(scope));
if (invalidScope) {
throw new DiscordjsTypeError(ErrorCodes.InvalidElement, 'Array', 'scopes', invalidScope);View on GitHub (pinned to a81ed8a306)
Solutions
- Always include scopes: [OAuth2Scopes.Bot] (plus others as needed) in the options object
- Check for a typo: the key must be exactly 'scopes' (plural)
- Import OAuth2Scopes from discord.js and use its enum values
Example fix
// before
const link = client.generateInvite({ permissions: ['ADMINISTRATOR'] });
// after
const { OAuth2Scopes } = require('discord.js');
const link = client.generateInvite({ scopes: [OAuth2Scopes.Bot], permissions: ['ADMINISTRATOR'] }); Defensive patterns
Strategy: validation
Validate before calling
if (!Array.isArray(opts?.scopes) || opts.scopes.length === 0) {
throw new Error('generateInvite requires scopes: [OAuth2Scopes.Bot]');
} Type guard
const hasScopes = (opts) => Array.isArray(opts?.scopes) && opts.scopes.length > 0;
Try / catch
try {
const link = client.generateInvite(opts);
} catch (err) {
if (err.code === 'InvalidMissingScopes') console.error('Add scopes, e.g. scopes: [OAuth2Scopes.Bot]');
else throw err;
} Prevention
- Always include scopes in the options object, even minimal [OAuth2Scopes.Bot]
- Use the OAuth2Scopes enum, never raw strings
- Double-check property name is 'scopes' (plural)
When it happens
Trigger: Calling client.generateInvite() with an options object that omits the scopes key, e.g. client.generateInvite({ permissions: [...] }).
Common situations: Building options dynamically and the scopes property name is misspelled (scope instead of scopes); copying old v12 examples where scopes were not part of the options object.
Understand the failure class
Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.
Related errors
AI-assisted analysis of discordjs/discord.js@a81ed8a306 (2026-08-30).
Data as JSON: /api/errors/e1d5b273a27f9053.
Report an issue: GitHub.