Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ClientOptions): waitGuildTimeout amount client option #6576

Merged
merged 43 commits into from Dec 24, 2021
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
3b846b9
fetch guild timeout amount option
kylerchin Sep 1, 2021
6d5a426
Update src/client/websocket/WebSocketShard.js
kylerchin Sep 1, 2021
08a088e
Options for client
kylerchin Sep 1, 2021
8805731
change to milliseconds
kylerchin Sep 1, 2021
2980212
additional timeout what zero means
kylerchin Sep 1, 2021
aa5b300
if not specified note
kylerchin Sep 1, 2021
f6ca9e9
Merge pull request #1 from discordjs/main
kylerchin Sep 1, 2021
0650264
Update src/client/websocket/WebSocketShard.js
kylerchin Sep 1, 2021
895da0d
fix line length lint issue
kylerchin Sep 1, 2021
ce80fc8
prettier style formatting
kylerchin Sep 1, 2021
32f6459
Add validation
kylerchin Sep 1, 2021
3a2c32a
Add default value
kylerchin Sep 1, 2021
5373716
Update src/client/websocket/WebSocketShard.js
kylerchin Sep 1, 2021
a8e686e
Update src/util/Options.js
kylerchin Sep 2, 2021
4460fdc
fix doccumentation
kylerchin Sep 3, 2021
e23cb90
Update src/client/websocket/WebSocketShard.js
kylerchin Sep 3, 2021
373f0d9
Update src/util/Options.js
kylerchin Sep 3, 2021
3e24cfc
Update src/util/Options.js
kylerchin Sep 4, 2021
10f0fcb
Update src/util/Options.js
kylerchin Sep 4, 2021
8b43ac7
Update src/client/websocket/WebSocketShard.js
kylerchin Sep 4, 2021
67113b3
Merge branch 'main' into main
kylerchin Sep 4, 2021
032c11a
add documentation on what skipping timeout means
kylerchin Sep 4, 2021
8ef317a
Update src/client/websocket/WebSocketShard.js
kylerchin Sep 5, 2021
032fd10
Update src/util/Options.js
kylerchin Sep 6, 2021
30df145
Merge pull request #2 from discordjs/main
kylerchin Sep 6, 2021
488bef4
Merge pull request #3 from discordjs/main
kylerchin Sep 16, 2021
2bae858
Update src/util/Options.js
kylerchin Sep 20, 2021
e52ba3d
Update Client.js
kylerchin Sep 20, 2021
c2a0fba
change name
kylerchin Sep 20, 2021
e16ec48
change fetch to wait
kylerchin Sep 20, 2021
5613b9f
change name again
kylerchin Sep 20, 2021
752c393
Update src/client/websocket/WebSocketShard.js
kylerchin Sep 21, 2021
3358b18
Update src/client/websocket/WebSocketShard.js
kylerchin Sep 21, 2021
0373bba
Update src/client/websocket/WebSocketShard.js
kylerchin Sep 21, 2021
477a6be
apply suggestions from code review
SpaceEEC Oct 3, 2021
f78cd74
Update WebSocketShard.js
kylerchin Oct 30, 2021
8f31b9f
Update Options.js
kylerchin Oct 30, 2021
0e53da5
Merge pull request #4 from discordjs/main
kylerchin Nov 23, 2021
e97ed36
Merge pull request #5 from discordjs/main
kylerchin Nov 27, 2021
dfeaa93
Update BaseGuild.js
kylerchin Nov 28, 2021
0e35afa
Update BaseGuild.js
kylerchin Nov 29, 2021
c94018a
Update Options.js
kylerchin Dec 23, 2021
7ce42b6
Merge branch 'main' into main
iCrawl Dec 24, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/client/Client.js
Expand Up @@ -567,6 +567,9 @@ class Client extends BaseClient {
if (!Array.isArray(options.partials)) {
throw new TypeError('CLIENT_INVALID_OPTION', 'partials', 'an Array');
}
if (typeof options.waitGuildTimeout !== 'number' || isNaN(options.waitGuildTimeout)) {
throw new TypeError('CLIENT_INVALID_OPTION', 'waitGuildTimeout', 'a number');
}
if (typeof options.restWsBridgeTimeout !== 'number' || isNaN(options.restWsBridgeTimeout)) {
throw new TypeError('CLIENT_INVALID_OPTION', 'restWsBridgeTimeout', 'a number');
}
Expand Down
14 changes: 11 additions & 3 deletions src/client/websocket/WebSocketShard.js
Expand Up @@ -475,12 +475,20 @@ class WebSocketShard extends EventEmitter {
return;
}
const hasGuildsIntent = new Intents(this.manager.client.options.intents).has(Intents.FLAGS.GUILDS);
// Step 2. Create a 15s timeout that will mark the shard as ready if there are still unavailable guilds
// Step 2. Create a timeout that will mark the shard as ready if there are still unavailable guilds
// * The timeout is 15 seconds by default
// * This can be optionally be changed in the client options via the `waitGuildTimeout` option
kylerchin marked this conversation as resolved.
Show resolved Hide resolved
// * a timeout time of zero will skip this timeout, which potentially could cause the Client to miss guilds.
kylerchin marked this conversation as resolved.
Show resolved Hide resolved

const { waitGuildTimeout } = this.manager.client.options;

this.readyTimeout = setTimeout(
() => {
this.debug(
`Shard ${hasGuildsIntent ? 'did' : 'will'} not receive any more guild packets` +
`${hasGuildsIntent ? ' in 15 seconds' : ''}.\n Unavailable guild count: ${this.expectedGuilds.size}`,
`${hasGuildsIntent ? ` in ${waitGuildTimeout} ms` : ''}.\nUnavailable guild count: ${
this.expectedGuilds.size
}`,
);

this.readyTimeout = null;
Expand All @@ -489,7 +497,7 @@ class WebSocketShard extends EventEmitter {

this.emit(ShardEvents.ALL_READY, this.expectedGuilds);
},
hasGuildsIntent ? 15_000 : 0,
hasGuildsIntent ? waitGuildTimeout : 0,
).unref();
}

Expand Down
2 changes: 2 additions & 0 deletions src/util/Options.js
Expand Up @@ -69,6 +69,8 @@
* [User Agent](https://discord.com/developers/docs/reference#user-agent) header
* @property {PresenceData} [presence={}] Presence data to use upon login
* @property {IntentsResolvable} intents Intents to enable for this connection
* @property {number} [waitGuildTimeout=15000] Time in milliseconds that Clients with the GUILDS intent should wait for
iCrawl marked this conversation as resolved.
Show resolved Hide resolved
* missing guilds to be recieved before starting the bot. If not specified, the default is 15 seconds.
iCrawl marked this conversation as resolved.
Show resolved Hide resolved
* @property {WebsocketOptions} [ws] Options for the WebSocket
* @property {HTTPOptions} [http] HTTP options
*/
Expand Down
1 change: 1 addition & 0 deletions typings/index.d.ts
Expand Up @@ -3353,6 +3353,7 @@ export interface ClientOptions {
userAgentSuffix?: string[];
presence?: PresenceData;
intents: BitFieldResolvable<IntentsString, number>;
waitGuildTimeout?: number;
ws?: WebSocketOptions;
http?: HTTPOptions;
rejectOnRateLimit?: string[] | ((data: RateLimitData) => boolean | Promise<boolean>);
Expand Down