From 451df42c40d58c9802f2c3c4afaddcf954000078 Mon Sep 17 00:00:00 2001 From: TetieWasTaken Date: Mon, 3 Apr 2023 21:46:38 +0200 Subject: [PATCH 1/5] chore: expand error feedback --- packages/discord.js/src/client/Client.js | 18 ++++++++++++++++++ packages/discord.js/src/errors/ErrorCodes.js | 2 ++ packages/discord.js/src/errors/Messages.js | 1 + 3 files changed, 21 insertions(+) diff --git a/packages/discord.js/src/client/Client.js b/packages/discord.js/src/client/Client.js index 2263e969c75b..a728b6f3cfe5 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,21 @@ class Client extends BaseClient { if (typeof options.failIfNotExists !== 'boolean') { throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'failIfNotExists', 'a boolean'); } + if (typeof options.allowedMentions !== 'object') { + throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'allowedMentions', 'an object'); + } + if (typeof options.presence !== 'object') { + throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'presence', 'an object'); + } + if (typeof options.ws !== 'object') { + throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'ws', 'an object'); + } + if (typeof options.rest !== 'object') { + 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..87a051aba703 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 {'InvalidScopeWithPermissions'} InvalidScopeWithPermissions * @property {'NotImplemented'} NotImplemented @@ -289,6 +290,7 @@ const keys = [ 'ModalSubmitInteractionFieldType', 'InvalidMissingScopes', + 'InvalidScopeWithPermissions', 'NotImplemented', diff --git a/packages/discord.js/src/errors/Messages.js b/packages/discord.js/src/errors/Messages.js index 1b79ec030023..0cdf2a36c3e6 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.InvalidScopeWithPermissions]: 'Permissions cannot be used without the bot scope', [DjsErrorCodes.NotImplemented]: (what, name) => `Method ${what} not implemented on ${name}.`, From 944892e8511b3daf9cbfa65559f00ac449bfa4a1 Mon Sep 17 00:00:00 2001 From: TetieWasTaken Date: Mon, 3 Apr 2023 22:02:52 +0200 Subject: [PATCH 2/5] fix: semantic change --- packages/discord.js/src/errors/Messages.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/discord.js/src/errors/Messages.js b/packages/discord.js/src/errors/Messages.js index 0cdf2a36c3e6..da955c161456 100644 --- a/packages/discord.js/src/errors/Messages.js +++ b/packages/discord.js/src/errors/Messages.js @@ -155,7 +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.InvalidScopeWithPermissions]: 'Permissions cannot be used without the bot scope', + [DjsErrorCodes.InvalidScopeWithPermissions]: 'Permissions cannot be set without the bot scope', [DjsErrorCodes.NotImplemented]: (what, name) => `Method ${what} not implemented on ${name}.`, From 21fd16e05a86536c4354c32de3fc6fb846c7d506 Mon Sep 17 00:00:00 2001 From: TetieWasTaken Date: Mon, 3 Apr 2023 21:46:38 +0200 Subject: [PATCH 3/5] chore: expand error feedback --- packages/discord.js/src/client/Client.js | 18 ++++++++++++++++++ packages/discord.js/src/errors/ErrorCodes.js | 2 ++ packages/discord.js/src/errors/Messages.js | 1 + 3 files changed, 21 insertions(+) diff --git a/packages/discord.js/src/client/Client.js b/packages/discord.js/src/client/Client.js index 28f01a1a0dfb..bc7f971c5b52 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,21 @@ class Client extends BaseClient { if (typeof options.failIfNotExists !== 'boolean') { throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'failIfNotExists', 'a boolean'); } + if (typeof options.allowedMentions !== 'object') { + throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'allowedMentions', 'an object'); + } + if (typeof options.presence !== 'object') { + throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'presence', 'an object'); + } + if (typeof options.ws !== 'object') { + throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'ws', 'an object'); + } + if (typeof options.rest !== 'object') { + 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..87a051aba703 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 {'InvalidScopeWithPermissions'} InvalidScopeWithPermissions * @property {'NotImplemented'} NotImplemented @@ -289,6 +290,7 @@ const keys = [ 'ModalSubmitInteractionFieldType', 'InvalidMissingScopes', + 'InvalidScopeWithPermissions', 'NotImplemented', diff --git a/packages/discord.js/src/errors/Messages.js b/packages/discord.js/src/errors/Messages.js index 1b79ec030023..0cdf2a36c3e6 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.InvalidScopeWithPermissions]: 'Permissions cannot be used without the bot scope', [DjsErrorCodes.NotImplemented]: (what, name) => `Method ${what} not implemented on ${name}.`, From d291e7466e66a59da8487f9ee57d0bf8e71efc78 Mon Sep 17 00:00:00 2001 From: TetieWasTaken Date: Mon, 3 Apr 2023 22:02:52 +0200 Subject: [PATCH 4/5] fix: semantic change --- packages/discord.js/src/errors/Messages.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/discord.js/src/errors/Messages.js b/packages/discord.js/src/errors/Messages.js index 0cdf2a36c3e6..da955c161456 100644 --- a/packages/discord.js/src/errors/Messages.js +++ b/packages/discord.js/src/errors/Messages.js @@ -155,7 +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.InvalidScopeWithPermissions]: 'Permissions cannot be used without the bot scope', + [DjsErrorCodes.InvalidScopeWithPermissions]: 'Permissions cannot be set without the bot scope', [DjsErrorCodes.NotImplemented]: (what, name) => `Method ${what} not implemented on ${name}.`, From 95ed35b179ce45d0e5729c948fb72784d079aaf5 Mon Sep 17 00:00:00 2001 From: TetieWasTaken Date: Fri, 14 Apr 2023 17:06:18 +0200 Subject: [PATCH 5/5] fix: make allowedMentions optional --- packages/discord.js/src/client/Client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/discord.js/src/client/Client.js b/packages/discord.js/src/client/Client.js index a728b6f3cfe5..9b0005b24d34 100644 --- a/packages/discord.js/src/client/Client.js +++ b/packages/discord.js/src/client/Client.js @@ -515,7 +515,7 @@ class Client extends BaseClient { if (typeof options.failIfNotExists !== 'boolean') { throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'failIfNotExists', 'a boolean'); } - if (typeof options.allowedMentions !== 'object') { + if (options.allowedMentions && typeof options.allowedMentions !== 'object') { throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'allowedMentions', 'an object'); } if (typeof options.presence !== 'object') {