feat(ClientOptions): Add messageCreateEventGuildTimeout`

Increase timeout each time WS send

If you don't want a timeout, set it to `0`

Co-Authored-By: Nguyễn Hồng Đức <hongducyb123@gmail.com>
This commit is contained in:
March 7th 2022-08-21 09:43:22 +07:00
parent 9f33ab1cfd
commit 1587b12d22
6 changed files with 13 additions and 9 deletions

View File

@ -35,7 +35,7 @@
### <strong>[Extend Document (With Example)](https://github.com/aiko-chan-ai/discord.js-selfbot-v13/tree/main/Document)</strong>
## Features
- [x] Message: Send, Recieve, Delete, Edit, Pin, Reaction Emoji, Attachments, Embeds (WebEmbed), Mentions, Webhooks, etc.
- [x] Message: Send, Receive, Delete, Edit, Pin, Reaction Emoji, Attachments, Embeds (WebEmbed), Mentions, Webhooks, etc.
- [x] User: Settings, Status, Activity, DeveloperPortal, RemoteAuth, etc.
- [X] Guild: Fetch Members, Join / Leave, Roles, Channels, etc.
- [X] Interactions: Slash Commands, Click Buttons, Using Menu, Modal, Context Menu, etc.

File diff suppressed because one or more lines are too long

View File

@ -918,6 +918,9 @@ class Client extends BaseClient {
if (typeof options.waitGuildTimeout !== 'number' || isNaN(options.waitGuildTimeout)) {
throw new TypeError('CLIENT_INVALID_OPTION', 'waitGuildTimeout', 'a number');
}
if (typeof options.messageCreateEventGuildTimeout !== 'number' || isNaN(options.messageCreateEventGuildTimeout)) {
throw new TypeError('CLIENT_INVALID_OPTION', 'messageCreateEventGuildTimeout', 'a number');
}
if (typeof options.restWsBridgeTimeout !== 'number' || isNaN(options.restWsBridgeTimeout)) {
throw new TypeError('CLIENT_INVALID_OPTION', 'restWsBridgeTimeout', 'a number');
}

View File

@ -59,7 +59,7 @@ async function checkUpdate(client) {
return client.emit('update', Discord.version, latest_tag);
}
module.exports = (client, { d: data }, shard) => {
module.exports = async (client, { d: data }, shard) => {
checkUpdate(client);
if (client.options.patchVoice && !running) {
@ -146,7 +146,8 @@ module.exports = (client, { d: data }, shard) => {
}
// Receive messages in large guilds
client.guilds.cache.map(guild => {
for (const guild of data.guilds) {
await client.sleep(client.options.messageCreateEventGuildTimeout);
client.ws.broadcast({
op: Opcodes.LAZY_REQUEST,
d: {
@ -156,13 +157,10 @@ module.exports = (client, { d: data }, shard) => {
activities: true,
thread_member_lists: [],
members: [],
channels: {
// [guild.channels.cache.first().id]: [[0, 99]],
},
channels: {},
},
});
return true;
});
}
client.relationships._setup(data.relationships);

View File

@ -81,6 +81,7 @@ const { randomUA } = require('../util/Constants');
* @property {PresenceData} [presence={}] Presence data to use upon login
* @property {IntentsResolvable} [intents=131071] Intents to enable for this connection (but not using)
* @property {number} [waitGuildTimeout=15000] Time in milliseconds that Clients with the GUILDS intent should wait for
* @property {number} [messageCreateEventGuildTimeout=100] Time in milliseconds that Clients to register for messages with each guild
* missing guilds to be received before starting the bot. If not specified, the default is 15 seconds.
* @property {SweeperOptions} [sweepers={}] Options for cache sweeping
* @property {WebsocketOptions} [ws] Options for the WebSocket
@ -149,6 +150,7 @@ class Options extends null {
DMSync: false,
patchVoice: true,
waitGuildTimeout: 15_000,
messageCreateEventGuildTimeout: 100,
shardCount: 1,
makeCache: this.cacheWithLimits(this.defaultMakeCacheSettings),
messageCacheLifetime: 0,

1
typings/index.d.ts vendored
View File

@ -4564,6 +4564,7 @@ export interface ClientOptions {
presence?: PresenceData;
intents?: BitFieldResolvable<IntentsString, number>;
waitGuildTimeout?: number;
messageCreateEventGuildTimeout?: number;
sweepers?: SweeperOptions;
ws?: WebSocketOptions;
http?: HTTPOptions;