diff --git a/packages/discord.js/src/client/Client.js b/packages/discord.js/src/client/Client.js index 28f01a1a0dfb..ddf8d3b7e468 100644 --- a/packages/discord.js/src/client/Client.js +++ b/packages/discord.js/src/client/Client.js @@ -420,6 +420,9 @@ class Client extends BaseClient { if (!scopes.some(scope => [OAuth2Scopes.Bot, OAuth2Scopes.ApplicationsCommands].includes(scope))) { throw new DiscordjsTypeError(ErrorCodes.InvalidMissingScopes); } + if (scopes.some(scope => ![OAuth2Scopes.Bot].includes(scope)) && options.permissions) { + throw new DiscordjsTypeError(ErrorCodes.InvalidScopeWithPermissions); + } const validScopes = Object.values(OAuth2Scopes); const invalidScope = scopes.find(scope => !validScopes.includes(scope)); if (invalidScope) { @@ -512,6 +515,24 @@ class Client extends BaseClient { if (typeof options.failIfNotExists !== 'boolean') { throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'failIfNotExists', 'a boolean'); } + if ( + (typeof options.allowedMentions !== 'object' && options.allowedMentions !== undefined) || + options.allowedMentions === null + ) { + throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'allowedMentions', 'an object'); + } + if (typeof options.presence !== 'object' || options.presence === null) { + throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'presence', 'an object'); + } + if (typeof options.ws !== 'object' || options.ws === null) { + throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'ws', 'an object'); + } + if (typeof options.rest !== 'object' || options.rest === null) { + throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'rest', 'an object'); + } + if (typeof options.jsonTransformer !== 'function') { + throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'jsonTransformer', 'a function'); + } } } diff --git a/packages/discord.js/src/errors/ErrorCodes.js b/packages/discord.js/src/errors/ErrorCodes.js index 3f074a1dad06..cb1a1f09d46e 100644 --- a/packages/discord.js/src/errors/ErrorCodes.js +++ b/packages/discord.js/src/errors/ErrorCodes.js @@ -142,6 +142,7 @@ * @property {'ModalSubmitInteractionFieldType'} ModalSubmitInteractionFieldType * @property {'InvalidMissingScopes'} InvalidMissingScopes + * @property {'InvalidScopesWithPermissions'} InvalidScopesWithPermissions * @property {'NotImplemented'} NotImplemented @@ -289,6 +290,7 @@ const keys = [ 'ModalSubmitInteractionFieldType', 'InvalidMissingScopes', + 'InvalidScopesWithPermissions', 'NotImplemented', diff --git a/packages/discord.js/src/errors/Messages.js b/packages/discord.js/src/errors/Messages.js index 1b79ec030023..afdeafea8050 100644 --- a/packages/discord.js/src/errors/Messages.js +++ b/packages/discord.js/src/errors/Messages.js @@ -155,6 +155,7 @@ const Messages = { `Field with custom id "${customId}" is of type: ${type}; expected ${expected}.`, [DjsErrorCodes.InvalidMissingScopes]: 'At least one valid scope must be provided for the invite', + [DjsErrorCodes.InvalidScopesWithPermissions]: 'Permissions cannot be set without the bot scope.', [DjsErrorCodes.NotImplemented]: (what, name) => `Method ${what} not implemented on ${name}.`, diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 47f500f7e5c1..03dfb211761f 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -3636,6 +3636,7 @@ export enum DiscordjsErrorCodes { ModalSubmitInteractionFieldType = 'ModalSubmitInteractionFieldType', InvalidMissingScopes = 'InvalidMissingScopes', + InvalidScopesWithPermissions = 'InvalidScopesWithPermissions', NotImplemented = 'NotImplemented',