From 93b84ae7a6bf2b5521daa8d38998db3fa1eb8aff Mon Sep 17 00:00:00 2001 From: Qjuh <76154676+Qjuh@users.noreply.github.com> Date: Sat, 19 Oct 2024 01:53:56 +0200 Subject: [PATCH] refactor!: fix several issues with /ws incorporation (#10556) BREAKING CHANGE: `Client#ping` is nullable now --- packages/discord.js/src/client/Client.js | 21 +++-- packages/discord.js/src/errors/ErrorCodes.js | 81 -------------------- packages/discord.js/typings/index.d.ts | 2 +- 3 files changed, 11 insertions(+), 93 deletions(-) diff --git a/packages/discord.js/src/client/Client.js b/packages/discord.js/src/client/Client.js index cec6ef95a..9db2739c3 100644 --- a/packages/discord.js/src/client/Client.js +++ b/packages/discord.js/src/client/Client.js @@ -105,14 +105,6 @@ class Client extends BaseClient { */ this.actions = new ActionsManager(this); - /** - * Shard helpers for the client (only if the process was spawned from a {@link ShardingManager}) - * @type {?ShardClientUtil} - */ - this.shard = process.env.SHARDING_MANAGER - ? ShardClientUtil.singleton(this, process.env.SHARDING_MANAGER_MODE) - : null; - /** * The user manager of this client * @type {UserManager} @@ -170,6 +162,14 @@ class Client extends BaseClient { */ this.ws = new WebSocketManager(wsOptions); + /** + * Shard helpers for the client (only if the process was spawned from a {@link ShardingManager}) + * @type {?ShardClientUtil} + */ + this.shard = process.env.SHARDING_MANAGER + ? ShardClientUtil.singleton(this, process.env.SHARDING_MANAGER_MODE) + : null; + /** * The voice manager of the client * @type {ClientVoiceManager} @@ -414,12 +414,11 @@ class Client extends BaseClient { /** * The average ping of all WebSocketShards - * @type {number} + * @type {?number} * @readonly */ get ping() { - const sum = this.pings.reduce((a, b) => a + b, 0); - return sum / this.pings.size; + return this.pings.size ? this.pings.reduce((a, b) => a + b, 0) / this.pings.size : null; } /** diff --git a/packages/discord.js/src/errors/ErrorCodes.js b/packages/discord.js/src/errors/ErrorCodes.js index c1552392a..f23b3232b 100644 --- a/packages/discord.js/src/errors/ErrorCodes.js +++ b/packages/discord.js/src/errors/ErrorCodes.js @@ -12,25 +12,8 @@ * @property {'TokenMissing'} TokenMissing * @property {'ApplicationCommandPermissionsTokenMissing'} ApplicationCommandPermissionsTokenMissing - * @property {'WSCloseRequested'} WSCloseRequested - * This property is deprecated. - * @property {'WSConnectionExists'} WSConnectionExists - * This property is deprecated. - * @property {'WSNotOpen'} WSNotOpen - * This property is deprecated. - * @property {'ManagerDestroyed'} ManagerDestroyed - * This property is deprecated. - * @property {'BitFieldInvalid'} BitFieldInvalid - * @property {'ShardingInvalid'} ShardingInvalid - * This property is deprecated. - * @property {'ShardingRequired'} ShardingRequired - * This property is deprecated. - * @property {'InvalidIntents'} InvalidIntents - * This property is deprecated. - * @property {'DisallowedIntents'} DisallowedIntents - * This property is deprecated. * @property {'ShardingNoShards'} ShardingNoShards * @property {'ShardingInProcess'} ShardingInProcess * @property {'ShardingInvalidEvalBroadcast'} ShardingInvalidEvalBroadcast @@ -49,30 +32,10 @@ * @property {'InviteOptionsMissingChannel'} InviteOptionsMissingChannel - * @property {'ButtonLabel'} ButtonLabel - * This property is deprecated. - * @property {'ButtonURL'} ButtonURL - * This property is deprecated. - * @property {'ButtonCustomId'} ButtonCustomId - * This property is deprecated. - - * @property {'SelectMenuCustomId'} SelectMenuCustomId - * This property is deprecated. - * @property {'SelectMenuPlaceholder'} SelectMenuPlaceholder - * This property is deprecated. - * @property {'SelectOptionLabel'} SelectOptionLabel - * This property is deprecated. - * @property {'SelectOptionValue'} SelectOptionValue - * This property is deprecated. - * @property {'SelectOptionDescription'} SelectOptionDescription - * This property is deprecated. - * @property {'InteractionCollectorError'} InteractionCollectorError * @property {'FileNotFound'} FileNotFound - * @property {'UserBannerNotFetched'} UserBannerNotFetched - * This property is deprecated. * @property {'UserNoDMChannel'} UserNoDMChannel * @property {'VoiceNotStageChannel'} VoiceNotStageChannel @@ -82,19 +45,11 @@ * @property {'ReqResourceType'} ReqResourceType - * @property {'ImageFormat'} ImageFormat - * This property is deprecated. - * @property {'ImageSize'} ImageSize - * This property is deprecated. - * @property {'MessageBulkDeleteType'} MessageBulkDeleteType * @property {'MessageContentType'} MessageContentType * @property {'MessageNonceRequired'} MessageNonceRequired * @property {'MessageNonceType'} MessageNonceType - * @property {'SplitMaxLen'} SplitMaxLen - * This property is deprecated. - * @property {'BanResolveId'} BanResolveId * @property {'FetchBanResolveId'} FetchBanResolveId @@ -128,16 +83,11 @@ * @property {'EmojiType'} EmojiType * @property {'EmojiManaged'} EmojiManaged * @property {'MissingManageGuildExpressionsPermission'} MissingManageGuildExpressionsPermission - * @property {'MissingManageEmojisAndStickersPermission'} MissingManageEmojisAndStickersPermission - * This property is deprecated. Use `MissingManageGuildExpressionsPermission` instead. * * @property {'NotGuildSticker'} NotGuildSticker * @property {'ReactionResolveUser'} ReactionResolveUser - * @property {'VanityURL'} VanityURL - * This property is deprecated. - * @property {'InviteResolveCode'} InviteResolveCode * @property {'InviteNotFound'} InviteNotFound @@ -152,8 +102,6 @@ * @property {'InteractionAlreadyReplied'} InteractionAlreadyReplied * @property {'InteractionNotReplied'} InteractionNotReplied - * @property {'InteractionEphemeralReplied'} InteractionEphemeralReplied - * This property is deprecated. * @property {'CommandInteractionOptionNotFound'} CommandInteractionOptionNotFound * @property {'CommandInteractionOptionType'} CommandInteractionOptionType @@ -192,17 +140,8 @@ const keys = [ 'TokenMissing', 'ApplicationCommandPermissionsTokenMissing', - 'WSCloseRequested', - 'WSConnectionExists', - 'WSNotOpen', - 'ManagerDestroyed', - 'BitFieldInvalid', - 'ShardingInvalid', - 'ShardingRequired', - 'InvalidIntents', - 'DisallowedIntents', 'ShardingNoShards', 'ShardingInProcess', 'ShardingInvalidEvalBroadcast', @@ -221,21 +160,10 @@ const keys = [ 'InviteOptionsMissingChannel', - 'ButtonLabel', - 'ButtonURL', - 'ButtonCustomId', - - 'SelectMenuCustomId', - 'SelectMenuPlaceholder', - 'SelectOptionLabel', - 'SelectOptionValue', - 'SelectOptionDescription', - 'InteractionCollectorError', 'FileNotFound', - 'UserBannerNotFetched', 'UserNoDMChannel', 'VoiceNotStageChannel', @@ -245,16 +173,11 @@ const keys = [ 'ReqResourceType', - 'ImageFormat', - 'ImageSize', - 'MessageBulkDeleteType', 'MessageContentType', 'MessageNonceRequired', 'MessageNonceType', - 'SplitMaxLen', - 'BanResolveId', 'FetchBanResolveId', @@ -288,14 +211,11 @@ const keys = [ 'EmojiType', 'EmojiManaged', 'MissingManageGuildExpressionsPermission', - 'MissingManageEmojisAndStickersPermission', 'NotGuildSticker', 'ReactionResolveUser', - 'VanityURL', - 'InviteResolveCode', 'InviteNotFound', @@ -310,7 +230,6 @@ const keys = [ 'InteractionAlreadyReplied', 'InteractionNotReplied', - 'InteractionEphemeralReplied', 'CommandInteractionOptionNotFound', 'CommandInteractionOptionType', diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 2ac75da47..ad512d8ed 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -985,7 +985,7 @@ export class Client extends BaseClient { public guilds: GuildManager; public lastPingTimestamp: number; public options: Omit & { intents: IntentsBitField }; - public get ping(): number; + public get ping(): number | null; public get readyAt(): If; public readyTimestamp: If; public sweepers: Sweepers;