mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 12:03:31 +01:00
chore(Client): robust error checking (#9390)
* chore: robust error checking * fix: check for null * chore: add period Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> * fix: check for undefined correctly * chore: robust error checking * fix: check for null * chore: add period Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> * fix: check for undefined correctly * fix: check for null * fix: update typings --------- Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
This commit is contained in:
@@ -420,6 +420,9 @@ class Client extends BaseClient {
|
|||||||
if (!scopes.some(scope => [OAuth2Scopes.Bot, OAuth2Scopes.ApplicationsCommands].includes(scope))) {
|
if (!scopes.some(scope => [OAuth2Scopes.Bot, OAuth2Scopes.ApplicationsCommands].includes(scope))) {
|
||||||
throw new DiscordjsTypeError(ErrorCodes.InvalidMissingScopes);
|
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 validScopes = Object.values(OAuth2Scopes);
|
||||||
const invalidScope = scopes.find(scope => !validScopes.includes(scope));
|
const invalidScope = scopes.find(scope => !validScopes.includes(scope));
|
||||||
if (invalidScope) {
|
if (invalidScope) {
|
||||||
@@ -512,6 +515,24 @@ class Client extends BaseClient {
|
|||||||
if (typeof options.failIfNotExists !== 'boolean') {
|
if (typeof options.failIfNotExists !== 'boolean') {
|
||||||
throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'failIfNotExists', 'a 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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -142,6 +142,7 @@
|
|||||||
* @property {'ModalSubmitInteractionFieldType'} ModalSubmitInteractionFieldType
|
* @property {'ModalSubmitInteractionFieldType'} ModalSubmitInteractionFieldType
|
||||||
|
|
||||||
* @property {'InvalidMissingScopes'} InvalidMissingScopes
|
* @property {'InvalidMissingScopes'} InvalidMissingScopes
|
||||||
|
* @property {'InvalidScopesWithPermissions'} InvalidScopesWithPermissions
|
||||||
|
|
||||||
* @property {'NotImplemented'} NotImplemented
|
* @property {'NotImplemented'} NotImplemented
|
||||||
|
|
||||||
@@ -289,6 +290,7 @@ const keys = [
|
|||||||
'ModalSubmitInteractionFieldType',
|
'ModalSubmitInteractionFieldType',
|
||||||
|
|
||||||
'InvalidMissingScopes',
|
'InvalidMissingScopes',
|
||||||
|
'InvalidScopesWithPermissions',
|
||||||
|
|
||||||
'NotImplemented',
|
'NotImplemented',
|
||||||
|
|
||||||
|
|||||||
@@ -155,6 +155,7 @@ const Messages = {
|
|||||||
`Field with custom id "${customId}" is of type: ${type}; expected ${expected}.`,
|
`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.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}.`,
|
[DjsErrorCodes.NotImplemented]: (what, name) => `Method ${what} not implemented on ${name}.`,
|
||||||
|
|
||||||
|
|||||||
1
packages/discord.js/typings/index.d.ts
vendored
1
packages/discord.js/typings/index.d.ts
vendored
@@ -3636,6 +3636,7 @@ export enum DiscordjsErrorCodes {
|
|||||||
ModalSubmitInteractionFieldType = 'ModalSubmitInteractionFieldType',
|
ModalSubmitInteractionFieldType = 'ModalSubmitInteractionFieldType',
|
||||||
|
|
||||||
InvalidMissingScopes = 'InvalidMissingScopes',
|
InvalidMissingScopes = 'InvalidMissingScopes',
|
||||||
|
InvalidScopesWithPermissions = 'InvalidScopesWithPermissions',
|
||||||
|
|
||||||
NotImplemented = 'NotImplemented',
|
NotImplemented = 'NotImplemented',
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user