Skip to content

Commit cafde77

Browse files
authored
refactor(Util)!: rename fetchRecommendedShards (#8298)
1 parent b7d4e55 commit cafde77

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

Diff for: packages/discord.js/src/sharding/ShardingManager.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const { setTimeout: sleep } = require('node:timers/promises');
88
const { Collection } = require('@discordjs/collection');
99
const Shard = require('./Shard');
1010
const { Error, TypeError, RangeError, ErrorCodes } = require('../errors');
11-
const { mergeDefault, fetchRecommendedShards } = require('../util/Util');
11+
const { mergeDefault, fetchRecommendedShardCount } = require('../util/Util');
1212

1313
/**
1414
* This is a utility class that makes multi-process sharding of a bot an easy and painless experience.
@@ -187,7 +187,7 @@ class ShardingManager extends EventEmitter {
187187
async spawn({ amount = this.totalShards, delay = 5500, timeout = 30_000 } = {}) {
188188
// Obtain/verify the number of shards to spawn
189189
if (amount === 'auto') {
190-
amount = await fetchRecommendedShards(this.token);
190+
amount = await fetchRecommendedShardCount(this.token);
191191
} else {
192192
if (typeof amount !== 'number' || isNaN(amount)) {
193193
throw new TypeError(ErrorCodes.ClientInvalidOption, 'Amount of shards', 'a number.');

Diff for: packages/discord.js/src/util/Util.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -211,18 +211,18 @@ function escapeSpoiler(text) {
211211
}
212212

213213
/**
214-
* @typedef {Object} FetchRecommendedShardsOptions
214+
* @typedef {Object} FetchRecommendedShardCountOptions
215215
* @property {number} [guildsPerShard=1000] Number of guilds assigned per shard
216216
* @property {number} [multipleOf=1] The multiple the shard count should round up to. (16 for large bot sharding)
217217
*/
218218

219219
/**
220220
* Gets the recommended shard count from Discord.
221221
* @param {string} token Discord auth token
222-
* @param {FetchRecommendedShardsOptions} [options] Options for fetching the recommended shard count
222+
* @param {FetchRecommendedShardCountOptions} [options] Options for fetching the recommended shard count
223223
* @returns {Promise<number>} The recommended number of shards
224224
*/
225-
async function fetchRecommendedShards(token, { guildsPerShard = 1_000, multipleOf = 1 } = {}) {
225+
async function fetchRecommendedShardCount(token, { guildsPerShard = 1_000, multipleOf = 1 } = {}) {
226226
if (!token) throw new DiscordError(ErrorCodes.TokenMissing);
227227
const response = await fetch(RouteBases.api + Routes.gatewayBot(), {
228228
method: 'GET',
@@ -555,7 +555,7 @@ module.exports = {
555555
escapeUnderline,
556556
escapeStrikethrough,
557557
escapeSpoiler,
558-
fetchRecommendedShards,
558+
fetchRecommendedShardCount,
559559
parseEmoji,
560560
resolvePartialEmoji,
561561
mergeDefault,

Diff for: packages/discord.js/typings/index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2290,7 +2290,7 @@ export class ShardingManager extends EventEmitter {
22902290
public once(event: 'shardCreate', listener: (shard: Shard) => Awaitable<void>): this;
22912291
}
22922292

2293-
export interface FetchRecommendedShardsOptions {
2293+
export interface FetchRecommendedShardCountOptions {
22942294
guildsPerShard?: number;
22952295
multipleOf?: number;
22962296
}
@@ -2640,7 +2640,7 @@ export function escapeUnderline(text: string): string;
26402640
export function escapeStrikethrough(text: string): string;
26412641
export function escapeSpoiler(text: string): string;
26422642
export function cleanCodeBlockContent(text: string): string;
2643-
export function fetchRecommendedShards(token: string, options?: FetchRecommendedShardsOptions): Promise<number>;
2643+
export function fetchRecommendedShardCount(token: string, options?: FetchRecommendedShardCountOptions): Promise<number>;
26442644
export function flatten(obj: unknown, ...props: Record<string, boolean | string>[]): unknown;
26452645
export function makeError(obj: MakeErrorOptions): Error;
26462646
export function makePlainError(err: Error): MakeErrorOptions;

0 commit comments

Comments
 (0)