djs-selfbot-v13 3.1.7 → 3.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +18 -45
  3. package/package.json +8 -37
  4. package/src/client/BaseClient.js +2 -3
  5. package/src/client/Client.js +187 -539
  6. package/src/client/actions/Action.js +18 -13
  7. package/src/client/actions/ActionsManager.js +7 -1
  8. package/src/client/actions/AutoModerationActionExecution.js +1 -0
  9. package/src/client/actions/AutoModerationRuleCreate.js +1 -0
  10. package/src/client/actions/AutoModerationRuleDelete.js +1 -0
  11. package/src/client/actions/AutoModerationRuleUpdate.js +1 -0
  12. package/src/client/actions/MessageCreate.js +0 -4
  13. package/src/client/actions/PresenceUpdate.js +17 -16
  14. package/src/client/websocket/WebSocketManager.js +11 -31
  15. package/src/client/websocket/WebSocketShard.js +39 -38
  16. package/src/client/websocket/handlers/CALL_CREATE.js +3 -3
  17. package/src/client/websocket/handlers/CALL_DELETE.js +2 -2
  18. package/src/client/websocket/handlers/CALL_UPDATE.js +2 -2
  19. package/src/client/websocket/handlers/CHANNEL_RECIPIENT_ADD.js +16 -13
  20. package/src/client/websocket/handlers/CHANNEL_RECIPIENT_REMOVE.js +11 -11
  21. package/src/client/websocket/handlers/GUILD_CREATE.js +7 -0
  22. package/src/client/websocket/handlers/INTERACTION_MODAL_CREATE.js +1 -0
  23. package/src/client/websocket/handlers/READY.js +47 -137
  24. package/src/client/websocket/handlers/RELATIONSHIP_ADD.js +7 -5
  25. package/src/client/websocket/handlers/RELATIONSHIP_REMOVE.js +6 -4
  26. package/src/client/websocket/handlers/RELATIONSHIP_UPDATE.js +32 -9
  27. package/src/client/websocket/handlers/USER_GUILD_SETTINGS_UPDATE.js +2 -8
  28. package/src/client/websocket/handlers/USER_NOTE_UPDATE.js +1 -1
  29. package/src/client/websocket/handlers/USER_REQUIRED_ACTION_UPDATE.js +78 -0
  30. package/src/client/websocket/handlers/USER_SETTINGS_UPDATE.js +1 -5
  31. package/src/client/websocket/handlers/VOICE_CHANNEL_STATUS_UPDATE.js +12 -0
  32. package/src/client/websocket/handlers/index.js +15 -20
  33. package/src/errors/Messages.js +24 -69
  34. package/src/index.js +12 -43
  35. package/src/managers/ApplicationCommandManager.js +9 -12
  36. package/src/managers/ApplicationCommandPermissionsManager.js +3 -11
  37. package/src/managers/ChannelManager.js +3 -4
  38. package/src/managers/ClientUserSettingManager.js +161 -279
  39. package/src/managers/GuildBanManager.js +1 -1
  40. package/src/managers/GuildChannelManager.js +2 -0
  41. package/src/managers/GuildForumThreadManager.js +22 -28
  42. package/src/managers/GuildMemberManager.js +40 -216
  43. package/src/managers/GuildSettingManager.js +22 -15
  44. package/src/managers/MessageManager.js +42 -44
  45. package/src/managers/PermissionOverwriteManager.js +1 -1
  46. package/src/managers/ReactionUserManager.js +5 -5
  47. package/src/managers/RelationshipManager.js +81 -74
  48. package/src/managers/ThreadManager.js +12 -45
  49. package/src/managers/ThreadMemberManager.js +1 -1
  50. package/src/managers/UserManager.js +6 -10
  51. package/src/managers/UserNoteManager.js +53 -0
  52. package/src/rest/APIRequest.js +42 -20
  53. package/src/rest/DiscordAPIError.js +17 -16
  54. package/src/rest/RESTManager.js +1 -21
  55. package/src/rest/RequestHandler.js +35 -21
  56. package/src/structures/ApplicationCommand.js +19 -456
  57. package/src/structures/ApplicationRoleConnectionMetadata.js +3 -0
  58. package/src/structures/AutoModerationRule.js +5 -5
  59. package/src/structures/AutocompleteInteraction.js +1 -0
  60. package/src/structures/BaseGuildTextChannel.js +10 -12
  61. package/src/structures/BaseGuildVoiceChannel.js +16 -18
  62. package/src/structures/{Call.js → CallState.js} +17 -12
  63. package/src/structures/CategoryChannel.js +2 -0
  64. package/src/structures/Channel.js +2 -3
  65. package/src/structures/ClientPresence.js +12 -8
  66. package/src/structures/ClientUser.js +117 -336
  67. package/src/structures/ContextMenuInteraction.js +1 -1
  68. package/src/structures/DMChannel.js +29 -92
  69. package/src/structures/ForumChannel.js +0 -10
  70. package/src/structures/GroupDMChannel.js +387 -0
  71. package/src/structures/Guild.js +135 -271
  72. package/src/structures/GuildAuditLogs.js +0 -5
  73. package/src/structures/GuildChannel.js +16 -2
  74. package/src/structures/GuildMember.js +27 -145
  75. package/src/structures/Interaction.js +1 -62
  76. package/src/structures/Invite.js +35 -52
  77. package/src/structures/Message.js +228 -202
  78. package/src/structures/MessageAttachment.js +11 -0
  79. package/src/structures/MessageButton.js +1 -67
  80. package/src/structures/MessageEmbed.js +1 -1
  81. package/src/structures/MessageMentions.js +3 -2
  82. package/src/structures/MessagePayload.js +4 -46
  83. package/src/structures/MessageReaction.js +1 -1
  84. package/src/structures/MessageSelectMenu.js +1 -252
  85. package/src/structures/Modal.js +75 -180
  86. package/src/structures/Presence.js +2 -2
  87. package/src/structures/RichPresence.js +14 -34
  88. package/src/structures/Role.js +18 -2
  89. package/src/structures/SelectMenuInteraction.js +2 -151
  90. package/src/structures/Team.js +0 -49
  91. package/src/structures/TextInputComponent.js +0 -70
  92. package/src/structures/ThreadChannel.js +0 -19
  93. package/src/structures/User.js +117 -345
  94. package/src/structures/UserContextMenuInteraction.js +2 -2
  95. package/src/structures/VoiceState.js +74 -39
  96. package/src/structures/WebEmbed.js +38 -52
  97. package/src/structures/Webhook.js +17 -11
  98. package/src/structures/interfaces/Application.js +146 -23
  99. package/src/structures/interfaces/TextBasedChannel.js +411 -256
  100. package/src/util/ApplicationFlags.js +1 -1
  101. package/src/util/AttachmentFlags.js +38 -0
  102. package/src/util/Constants.js +106 -284
  103. package/src/util/Formatters.js +16 -2
  104. package/src/util/InviteFlags.js +29 -0
  105. package/src/util/LimitedCollection.js +1 -1
  106. package/src/util/Options.js +48 -68
  107. package/src/util/Permissions.js +5 -0
  108. package/src/util/PurchasedFlags.js +2 -0
  109. package/src/util/RemoteAuth.js +221 -356
  110. package/src/util/RoleFlags.js +37 -0
  111. package/src/util/Sweepers.js +1 -1
  112. package/src/util/Util.js +76 -36
  113. package/typings/enums.d.ts +18 -73
  114. package/typings/index.d.ts +873 -1225
  115. package/typings/rawDataTypes.d.ts +68 -9
  116. package/src/client/actions/InteractionCreate.js +0 -115
  117. package/src/client/websocket/handlers/APPLICATION_COMMAND_AUTOCOMPLETE_RESPONSE.js +0 -23
  118. package/src/client/websocket/handlers/GUILD_APPLICATION_COMMANDS_UPDATE.js +0 -11
  119. package/src/client/websocket/handlers/GUILD_MEMBER_LIST_UPDATE.js +0 -55
  120. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUNDS_UPDATE.js +0 -0
  121. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_CREATE.js +0 -0
  122. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_DELETE.js +0 -0
  123. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_UPDATE.js +0 -0
  124. package/src/client/websocket/handlers/INTERACTION_CREATE.js +0 -16
  125. package/src/client/websocket/handlers/INTERACTION_FAILURE.js +0 -18
  126. package/src/client/websocket/handlers/INTERACTION_SUCCESS.js +0 -30
  127. package/src/client/websocket/handlers/MESSAGE_ACK.js +0 -16
  128. package/src/client/websocket/handlers/SOUNDBOARD_SOUNDS.js +0 -0
  129. package/src/client/websocket/handlers/VOICE_CHANNEL_EFFECT_SEND.js +0 -0
  130. package/src/managers/DeveloperPortalManager.js +0 -104
  131. package/src/managers/GuildApplicationCommandManager.js +0 -28
  132. package/src/managers/GuildFolderManager.js +0 -24
  133. package/src/managers/SessionManager.js +0 -57
  134. package/src/rest/CaptchaSolver.js +0 -132
  135. package/src/structures/ClientApplication.js +0 -204
  136. package/src/structures/DeveloperPortalApplication.js +0 -520
  137. package/src/structures/GuildFolder.js +0 -75
  138. package/src/structures/InteractionResponse.js +0 -114
  139. package/src/structures/PartialGroupDMChannel.js +0 -433
  140. package/src/structures/Session.js +0 -81
  141. package/src/util/Voice.js +0 -1456
  142. package/src/util/arRPC/index.js +0 -229
  143. package/src/util/arRPC/process/detectable.json +0 -1
  144. package/src/util/arRPC/process/index.js +0 -102
  145. package/src/util/arRPC/process/native/index.js +0 -5
  146. package/src/util/arRPC/process/native/linux.js +0 -37
  147. package/src/util/arRPC/process/native/win32.js +0 -25
  148. package/src/util/arRPC/transports/ipc.js +0 -281
  149. package/src/util/arRPC/transports/websocket.js +0 -128
@@ -32,26 +32,31 @@ class GenericAction {
32
32
  }
33
33
 
34
34
  getChannel(data) {
35
+ const payloadData = {};
35
36
  const id = data.channel_id ?? data.id;
37
+
38
+ if ('recipients' in data) {
39
+ payloadData.recipients = data.recipients;
40
+ } else {
41
+ // Try to resolve the recipient, but do not add the client user.
42
+ const recipient = data.author ?? data.user ?? { id: data.user_id };
43
+ if (recipient.id !== this.client.user.id) payloadData.recipients = [recipient];
44
+ }
45
+
46
+ if (id !== undefined) payloadData.id = id;
47
+ if ('guild_id' in data) payloadData.guild_id = data.guild_id;
48
+ if ('last_message_id' in data) payloadData.last_message_id = data.last_message_id;
49
+
36
50
  return (
37
- data.channel ??
38
- this.getPayload(
39
- {
40
- id,
41
- guild_id: data.guild_id,
42
- recipients: [data.author ?? data.user ?? { id: data.user_id }],
43
- },
44
- this.client.channels,
45
- id,
46
- PartialTypes.CHANNEL,
47
- )
51
+ data[this.client.actions.injectedChannel] ??
52
+ this.getPayload(payloadData, this.client.channels, id, PartialTypes.CHANNEL)
48
53
  );
49
54
  }
50
55
 
51
56
  getMessage(data, channel, cache) {
52
57
  const id = data.message_id ?? data.id;
53
58
  return (
54
- data.message ??
59
+ data[this.client.actions.injectedMessage] ??
55
60
  this.getPayload(
56
61
  {
57
62
  id,
@@ -86,7 +91,7 @@ class GenericAction {
86
91
 
87
92
  getUser(data) {
88
93
  const id = data.user_id;
89
- return data.user ?? this.getPayload({ id }, this.client.users, id, PartialTypes.USER);
94
+ return data[this.client.actions.injectedUser] ?? this.getPayload({ id }, this.client.users, id, PartialTypes.USER);
90
95
  }
91
96
 
92
97
  getUserFromMember(data) {
@@ -4,6 +4,13 @@ class ActionsManager {
4
4
  constructor(client) {
5
5
  this.client = client;
6
6
 
7
+ // These symbols represent fully built data that we inject at times when calling actions manually.
8
+ // Action#getUser for example, will return the injected data (which is assumed to be a built structure)
9
+ // instead of trying to make it from provided data
10
+ this.injectedUser = Symbol('djs.actions.injectedUser');
11
+ this.injectedChannel = Symbol('djs.actions.injectedChannel');
12
+ this.injectedMessage = Symbol('djs.actions.injectedMessage');
13
+
7
14
  this.register(require('./ApplicationCommandPermissionsUpdate'));
8
15
  this.register(require('./AutoModerationActionExecution'));
9
16
  this.register(require('./AutoModerationRuleCreate'));
@@ -38,7 +45,6 @@ class ActionsManager {
38
45
  this.register(require('./GuildStickerUpdate'));
39
46
  this.register(require('./GuildStickersUpdate'));
40
47
  this.register(require('./GuildUpdate'));
41
- this.register(require('./InteractionCreate'));
42
48
  this.register(require('./InviteCreate'));
43
49
  this.register(require('./InviteDelete'));
44
50
  this.register(require('./MessageCreate'));
@@ -15,6 +15,7 @@ class AutoModerationActionExecutionAction extends Action {
15
15
  * <info>This event requires the {@link Permissions.FLAGS.MANAGE_GUILD} permission.</info>
16
16
  * @event Client#autoModerationActionExecution
17
17
  * @param {AutoModerationActionExecution} autoModerationActionExecution The data of the execution
18
+ * @deprecated This event is not received by user accounts.
18
19
  */
19
20
  client.emit(Events.AUTO_MODERATION_ACTION_EXECUTION, new AutoModerationActionExecution(data, guild));
20
21
  }
@@ -16,6 +16,7 @@ class AutoModerationRuleCreateAction extends Action {
16
16
  * <info>This event requires the {@link Permissions.FLAGS.MANAGE_GUILD} permission.</info>
17
17
  * @event Client#autoModerationRuleCreate
18
18
  * @param {AutoModerationRule} autoModerationRule The created auto moderation rule
19
+ * @deprecated This event is not received by user accounts.
19
20
  */
20
21
  client.emit(Events.AUTO_MODERATION_RULE_CREATE, autoModerationRule);
21
22
  }
@@ -19,6 +19,7 @@ class AutoModerationRuleDeleteAction extends Action {
19
19
  * <info>This event requires the {@link Permissions.FLAGS.MANAGE_GUILD} permission.</info>
20
20
  * @event Client#autoModerationRuleDelete
21
21
  * @param {AutoModerationRule} autoModerationRule The deleted auto moderation rule
22
+ * @deprecated This event is not received by user accounts.
22
23
  */
23
24
  client.emit(Events.AUTO_MODERATION_RULE_DELETE, autoModerationRule);
24
25
  }
@@ -18,6 +18,7 @@ class AutoModerationRuleUpdateAction extends Action {
18
18
  * @event Client#autoModerationRuleUpdate
19
19
  * @param {?AutoModerationRule} oldAutoModerationRule The auto moderation rule before the update
20
20
  * @param {AutoModerationRule} newAutoModerationRule The auto moderation rule after the update
21
+ * @deprecated This event is not received by user accounts.
21
22
  */
22
23
  client.emit(Events.AUTO_MODERATION_RULE_UPDATE, oldAutoModerationRule, newAutoModerationRule);
23
24
  }
@@ -18,10 +18,6 @@ class MessageCreateAction extends Action {
18
18
  const message = channel.messages._add(data);
19
19
  channel.lastMessageId = data.id;
20
20
 
21
- if (client.options.autoRedeemNitro) {
22
- client.autoRedeemNitro(message, channel);
23
- }
24
-
25
21
  /**
26
22
  * Emitted whenever a message is created.
27
23
  * @event Client#messageCreate
@@ -13,11 +13,9 @@ class PresenceUpdateAction extends Action {
13
13
  if (!user._equals(data.user)) this.client.actions.UserUpdate.handle(data.user);
14
14
  }
15
15
 
16
- // Shet, user not received guild_id
17
- let emited = false;
18
- for (const guild of this.client.guilds.cache.map(g => g)) {
19
- if (!guild.members.cache.get(user.id)) continue;
20
- const oldPresence = guild.presences.cache.get(user.id)?._clone() ?? null;
16
+ const guild = this.client.guilds.cache.get(data.guild_id);
17
+
18
+ if (guild) {
21
19
  let member = guild.members.cache.get(user.id);
22
20
  if (!member && data.status !== 'offline') {
23
21
  member = guild.members._add({
@@ -27,17 +25,20 @@ class PresenceUpdateAction extends Action {
27
25
  });
28
26
  this.client.emit(Events.GUILD_MEMBER_AVAILABLE, member);
29
27
  }
30
- const newPresence = guild.presences._add(Object.assign(data, { guild }));
31
- if (this.client.listenerCount(Events.PRESENCE_UPDATE) && !newPresence.equals(oldPresence) && !emited) {
32
- /**
33
- * Emitted whenever a guild member's presence (e.g. status, activity) is changed.
34
- * @event Client#presenceUpdate
35
- * @param {?Presence} oldPresence The presence before the update, if one at all
36
- * @param {Presence} newPresence The presence after the update
37
- */
38
- this.client.emit(Events.PRESENCE_UPDATE, oldPresence, newPresence);
39
- emited = true;
40
- }
28
+ }
29
+
30
+ const oldPresence = (guild || this.client).presences.cache.get(user.id)?._clone() ?? null;
31
+
32
+ const newPresence = (guild || this.client).presences._add(Object.assign(data, { guild }));
33
+
34
+ if (this.client.listenerCount(Events.PRESENCE_UPDATE) && !newPresence.equals(oldPresence)) {
35
+ /**
36
+ * Emitted whenever a guild member's presence (e.g. status, activity) is changed.
37
+ * @event Client#presenceUpdate
38
+ * @param {?Presence} oldPresence The presence before the update, if one at all
39
+ * @param {Presence} newPresence The presence after the update
40
+ */
41
+ this.client.emit(Events.PRESENCE_UPDATE, oldPresence, newPresence);
41
42
  }
42
43
  }
43
44
  }
@@ -126,36 +126,15 @@ class WebSocketManager extends EventEmitter {
126
126
  * @private
127
127
  */
128
128
  async connect() {
129
- // eslint-disable-next-line no-unused-vars
130
- const invalidToken = new Error(WSCodes[4004]);
131
- /*
132
- BOT
133
- const {
134
- url: gatewayURL,
135
- shards: recommendedShards,
136
- session_start_limit: sessionStartLimit,
137
- } = await this.client.api.gateway.bot.get().catch(error => {
138
- throw error.httpStatus === 401 ? invalidToken : error;
139
- });
140
- */
141
-
142
129
  let gatewayURL = 'wss://gateway.discord.gg';
143
- const { url } = await this.client.api.gateway.get({ auth: false }).catch(() => ({ url: gatewayURL }));
144
- // eslint-disable-next-line no-unused-vars
145
- /*
146
- .catch(error => {
147
- // Never throw error :v
148
- // throw error.httpStatus === 401 ? invalidToken : error;
149
- });
150
- */
151
- if (url) gatewayURL = url;
152
- const recommendedShards = 1;
153
- const sessionStartLimit = {
154
- total: Infinity,
155
- remaining: Infinity,
156
- };
130
+ await this.client.api.gateway
131
+ .get({ auth: false })
132
+ .then(r => (gatewayURL = r.url))
133
+ .catch(() => {});
157
134
 
158
- const { total, remaining } = sessionStartLimit;
135
+ const total = Infinity;
136
+ const remaining = Infinity;
137
+ const recommendedShards = 1;
159
138
 
160
139
  this.debug(`Fetched Gateway Information
161
140
  URL: ${gatewayURL}
@@ -294,7 +273,7 @@ class WebSocketManager extends EventEmitter {
294
273
  } catch (error) {
295
274
  this.debug(`Couldn't reconnect or fetch information about the gateway. ${error}`);
296
275
  if (error.httpStatus !== 401) {
297
- this.debug('Possible network error occurred. Retrying in 5s...');
276
+ this.debug(`Possible network error occurred. Retrying in 5s...`);
298
277
  await sleep(5_000);
299
278
  this.reconnecting = false;
300
279
  return this.reconnect();
@@ -368,11 +347,12 @@ class WebSocketManager extends EventEmitter {
368
347
  /**
369
348
  * Emitted whenever a packet isn't handled.
370
349
  * @event Client#unhandledPacket
371
- * @param {Object} packet The packet (t: Event name, d: Data)
372
- * @param {Number} shard The shard that received the packet (Auto = 0)
350
+ * @param {Object} packet The packet (t: EVENT_NAME, d: any)
351
+ * @param {Number} shard The shard that received the packet (Shard 0)
373
352
  */
374
353
  this.client.emit(Events.UNHANDLED_PACKET, packet, shard);
375
354
  }
355
+
376
356
  return true;
377
357
  }
378
358
 
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const EventEmitter = require('node:events');
4
+ const http = require('node:http');
4
5
  const { setTimeout, setInterval, clearTimeout } = require('node:timers');
5
6
  const WebSocket = require('../../WebSocket');
6
7
  const { Status, Events, ShardEvents, Opcodes, WSEvents, WSCodes } = require('../../util/Constants');
@@ -17,6 +18,7 @@ try {
17
18
 
18
19
  /**
19
20
  * Represents a Shard's WebSocket connection
21
+ * @extends {EventEmitter}
20
22
  */
21
23
  class WebSocketShard extends EventEmitter {
22
24
  constructor(manager, id) {
@@ -34,6 +36,13 @@ class WebSocketShard extends EventEmitter {
34
36
  */
35
37
  this.id = id;
36
38
 
39
+ /**
40
+ * The resume URL for this shard
41
+ * @type {?string}
42
+ * @private
43
+ */
44
+ this.resumeURL = null;
45
+
37
46
  /**
38
47
  * The current status of the shard
39
48
  * @type {Status}
@@ -61,13 +70,6 @@ class WebSocketShard extends EventEmitter {
61
70
  */
62
71
  this.sessionId = null;
63
72
 
64
- /**
65
- * URL to use when resuming
66
- * @type {?string}
67
- * @private
68
- */
69
- this.resumeURL = null;
70
-
71
73
  /**
72
74
  * The previous heartbeat ping of the shard
73
75
  * @type {number}
@@ -199,12 +201,12 @@ class WebSocketShard extends EventEmitter {
199
201
  connect() {
200
202
  const { client } = this.manager;
201
203
 
202
- const gateway = this.resumeURL ?? this.manager.gateway;
203
-
204
204
  if (this.connection?.readyState === WebSocket.OPEN && this.status === Status.READY) {
205
205
  return Promise.resolve();
206
206
  }
207
207
 
208
+ const gateway = this.resumeURL ?? this.manager.gateway;
209
+
208
210
  return new Promise((resolve, reject) => {
209
211
  const cleanup = () => {
210
212
  this.removeListener(ShardEvents.CLOSE, onClose);
@@ -270,7 +272,7 @@ class WebSocketShard extends EventEmitter {
270
272
  Version : ${client.options.ws.version}
271
273
  Encoding : ${WebSocket.encoding}
272
274
  Compression: ${zlib ? 'zlib-stream' : 'none'}
273
- Proxy : ${client.options.proxy || 'none'}`,
275
+ Agent : ${client.options.ws.agent instanceof http.Agent}`,
274
276
  );
275
277
 
276
278
  this.status = this.status === Status.DISCONNECTED ? Status.RECONNECTING : Status.CONNECTING;
@@ -278,14 +280,11 @@ class WebSocketShard extends EventEmitter {
278
280
  this.setWsCloseTimeout(-1);
279
281
  this.connectedAt = Date.now();
280
282
 
281
- let args = { handshakeTimeout: 30_000 };
282
- if (client.options.proxy.length > 0) {
283
- const proxy = require('proxy-agent');
284
- args.agent = new proxy(client.options.proxy);
285
- this.debug(`Using proxy ${client.options.proxy}`, args);
286
- }
287
283
  // Adding a handshake timeout to just make sure no zombie connection appears.
288
- const ws = (this.connection = WebSocket.create(gateway, wsQuery, args));
284
+ const ws = (this.connection = WebSocket.create(gateway, wsQuery, {
285
+ handshakeTimeout: 30_000,
286
+ agent: client.options.ws.agent instanceof http.Agent ? client.options.ws.agent : undefined,
287
+ }));
289
288
  ws.onopen = this.onOpen.bind(this);
290
289
  ws.onmessage = this.onMessage.bind(this);
291
290
  ws.onerror = this.onError.bind(this);
@@ -433,11 +432,11 @@ class WebSocketShard extends EventEmitter {
433
432
  */
434
433
  this.emit(ShardEvents.READY);
435
434
 
436
- this.sessionId = packet.d.session_id;
437
435
  this.resumeURL = packet.d.resume_gateway_url;
436
+ this.sessionId = packet.d.session_id;
438
437
  this.expectedGuilds = new Set(packet.d.guilds.filter(d => d?.unavailable == true).map(d => d.id));
439
438
  this.status = Status.WAITING_FOR_GUILDS;
440
- this.debug(`[READY] Session ${this.sessionId} | ResumeURL ${this.resumeURL}`);
439
+ this.debug(`[READY] Session ${this.sessionId} | Resume url ${this.resumeURL}.`);
441
440
  this.lastHeartbeatAcked = true;
442
441
  this.sendHeartbeat('ReadyHeartbeat');
443
442
  break;
@@ -538,21 +537,23 @@ class WebSocketShard extends EventEmitter {
538
537
 
539
538
  const { waitGuildTimeout } = this.manager.client.options;
540
539
 
541
- this.readyTimeout = setTimeout(() => {
542
- this.debug(
543
- `Shard ${hasGuildsIntent ? 'did' : 'will'} not receive any more guild packets` +
544
- `${hasGuildsIntent ? ` in ${waitGuildTimeout} ms` : ''}.\nUnavailable guild count: ${
545
- this.expectedGuilds.size
546
- }`,
547
- );
540
+ this.readyTimeout = setTimeout(
541
+ () => {
542
+ this.debug(
543
+ `Shard ${hasGuildsIntent ? 'did' : 'will'} not receive any more guild packets` +
544
+ `${hasGuildsIntent ? ` in ${waitGuildTimeout} ms` : ''}.\nUnavailable guild count: ${
545
+ this.expectedGuilds.size
546
+ }`,
547
+ );
548
548
 
549
- this.readyTimeout = null;
549
+ this.readyTimeout = null;
550
550
 
551
- this.status = Status.READY;
551
+ this.status = Status.READY;
552
552
 
553
- this.emit(ShardEvents.ALL_READY, this.expectedGuilds);
554
- // }, hasGuildsIntent && waitGuildTimeout).unref();
555
- }, waitGuildTimeout).unref();
553
+ this.emit(ShardEvents.ALL_READY, this.expectedGuilds);
554
+ },
555
+ hasGuildsIntent ? waitGuildTimeout : 0,
556
+ ).unref();
556
557
  }
557
558
 
558
559
  /**
@@ -593,6 +594,7 @@ class WebSocketShard extends EventEmitter {
593
594
  }
594
595
  this.wsCloseTimeout = setTimeout(() => {
595
596
  this.setWsCloseTimeout(-1);
597
+
596
598
  // Check if close event was emitted.
597
599
  if (this.closeEmitted) {
598
600
  this.debug(`[WebSocket] close was already emitted, assuming the connection was closed properly.`);
@@ -656,7 +658,6 @@ class WebSocketShard extends EventEmitter {
656
658
  Sequence : ${this.sequence}
657
659
  Connection State: ${this.connection ? CONNECTION_STATE[this.connection.readyState] : 'No Connection??'}`,
658
660
  );
659
-
660
661
  this.destroy({ reset: true, closeCode: 4009 });
661
662
  return;
662
663
  }
@@ -700,25 +701,24 @@ class WebSocketShard extends EventEmitter {
700
701
 
701
702
  this.status = Status.IDENTIFYING;
702
703
 
704
+ // Patch something
703
705
  Object.keys(client.options.ws.properties)
704
706
  .filter(k => k.startsWith('$'))
705
707
  .forEach(k => {
706
708
  client.options.ws.properties[k.slice(1)] = client.options.ws.properties[k];
707
709
  delete client.options.ws.properties[k];
708
710
  });
711
+
712
+ // Clone the identify payload and assign the token and shard info
709
713
  const d = {
710
- presence: client.options.presence,
711
714
  ...client.options.ws,
712
715
  token: client.token,
713
716
  };
714
717
 
715
718
  delete d.version;
719
+ delete d.agent;
716
720
 
717
- this.debug(
718
- `[IDENTIFY] Shard ${this.id}/${client.options.shardCount} with intents: ${Intents.resolve(
719
- client.options.intents,
720
- )} 😊`,
721
- );
721
+ this.debug(`[IDENTIFY] Shard ${this.id}`);
722
722
  this.send({ op: Opcodes.IDENTIFY, d }, true);
723
723
  }
724
724
 
@@ -815,6 +815,7 @@ class WebSocketShard extends EventEmitter {
815
815
  // Step 0: Remove all timers
816
816
  this.setHeartbeatTimer(-1);
817
817
  this.setHelloTimeout(-1);
818
+
818
819
  this.debug(
819
820
  `[WebSocket] Destroy: Attempting to close the WebSocket. | WS State: ${
820
821
  CONNECTION_STATE[this.connection?.readyState ?? WebSocket.CLOSED]
@@ -1,5 +1,5 @@
1
1
  'use strict';
2
- const Call = require('../../../structures/Call');
2
+ const CallState = require('../../../structures/CallState');
3
3
  const { Events } = require('../../../util/Constants');
4
4
  module.exports = (client, packet) => {
5
5
  for (const voice of packet.d.voice_states) {
@@ -8,7 +8,7 @@ module.exports = (client, packet) => {
8
8
  /**
9
9
  * Emitted whenever received a call
10
10
  * @event Client#callCreate
11
- * @param {Call} call Call
11
+ * @param {CallState} call Call
12
12
  */
13
- client.emit(Events.CALL_CREATE, new Call(client, packet.d));
13
+ client.emit(Events.CALL_CREATE, new CallState(client, packet.d));
14
14
  };
@@ -1,5 +1,5 @@
1
1
  'use strict';
2
- const Call = require('../../../structures/Call');
2
+ const CallState = require('../../../structures/CallState');
3
3
  const { Events } = require('../../../util/Constants');
4
4
  module.exports = (client, packet) => {
5
5
  /**
@@ -7,5 +7,5 @@ module.exports = (client, packet) => {
7
7
  * @event Client#callDelete
8
8
  * @param {Call} call Call
9
9
  */
10
- client.emit(Events.CALL_DELETE, new Call(client, packet.d));
10
+ client.emit(Events.CALL_DELETE, new CallState(client, packet.d));
11
11
  };
@@ -1,5 +1,5 @@
1
1
  'use strict';
2
- const Call = require('../../../structures/Call');
2
+ const CallState = require('../../../structures/CallState');
3
3
  const { Events } = require('../../../util/Constants');
4
4
  module.exports = (client, packet) => {
5
5
  /**
@@ -7,5 +7,5 @@ module.exports = (client, packet) => {
7
7
  * @event Client#callUpdate
8
8
  * @param {Call} call Call
9
9
  */
10
- client.emit(Events.CALL_UPDATE, new Call(client, packet.d));
10
+ client.emit(Events.CALL_UPDATE, new CallState(client, packet.d));
11
11
  };
@@ -1,16 +1,19 @@
1
1
  'use strict';
2
- const { Events } = require('../../../util/Constants');
3
- module.exports = (client, packet) => {
4
- /**
5
- * Emitted whenever a recipient is added from a group DM.
6
- * @event Client#channelRecipientAdd
7
- * @param {PartialGroupDMChannel} channel Group DM channel
8
- * @param {User} user User
9
- */
2
+ const { Events, Status } = require('../../../util/Constants');
3
+ module.exports = (client, packet, shard) => {
10
4
  const channel = client.channels.cache.get(packet.d.channel_id);
11
- if (!channel) return;
12
- if (!channel._recipients) channel._recipients = [];
13
- channel._recipients.push(packet.d.user);
14
- const user = client.users._add(packet.d.user);
15
- client.emit(Events.CHANNEL_RECIPIENT_ADD, channel, user);
5
+ if (channel) {
6
+ if (!channel._recipients) channel._recipients = [];
7
+ channel._recipients.push(packet.d.user);
8
+ const user = client.users._add(packet.d.user);
9
+ if (shard.status == Status.READY) {
10
+ /**
11
+ * Emitted whenever a recipient is added from a group DM.
12
+ * @event Client#channelRecipientAdd
13
+ * @param {GroupDMChannel} channel Group DM channel
14
+ * @param {User} user User
15
+ */
16
+ client.emit(Events.CHANNEL_RECIPIENT_ADD, channel, user);
17
+ }
18
+ }
16
19
  };
@@ -1,16 +1,16 @@
1
1
  'use strict';
2
2
  const { Events } = require('../../../util/Constants');
3
3
  module.exports = (client, packet) => {
4
- /**
5
- * Emitted whenever a recipient is removed from a group DM.
6
- * @event Client#channelRecipientRemove
7
- * @param {PartialGroupDMChannel} channel Group DM channel
8
- * @param {User} user User
9
- */
10
4
  const channel = client.channels.cache.get(packet.d.channel_id);
11
- if (!channel) return;
12
- if (!channel._recipients) channel._recipients = [];
13
- channel._recipients = channel._recipients.filter(r => r !== packet.d.user.id);
14
- const user = client.users._add(packet.d.user);
15
- client.emit(Events.CHANNEL_RECIPIENT_REMOVE, channel, user);
5
+ if (channel) {
6
+ if (!channel._recipients) channel._recipients = [];
7
+ channel._recipients = channel._recipients.filter(u => u.id !== packet.d.user.id);
8
+ /**
9
+ * Emitted whenever a recipient is removed from a group DM.
10
+ * @event Client#channelRecipientRemove
11
+ * @param {GroupDMChannel} channel Group DM channel
12
+ * @param {User} user User
13
+ */
14
+ client.emit(Events.CHANNEL_RECIPIENT_REMOVE, channel, client.users._add(packet.d.user));
15
+ }
16
16
  };
@@ -28,6 +28,13 @@ module.exports = (client, { d: data }, shard) => {
28
28
  // A newly available guild
29
29
  guild._patch(data);
30
30
  run(client, guild);
31
+
32
+ /**
33
+ * Emitted whenever a guild becomes available.
34
+ * @event Client#guildAvailable
35
+ * @param {Guild} guild The guild that became available
36
+ */
37
+ client.emit(Events.GUILD_AVAILABLE, guild);
31
38
  }
32
39
  } else {
33
40
  // A new guild
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
  const Modal = require('../../../structures/Modal');
3
3
  const { Events } = require('../../../util/Constants');
4
+
4
5
  module.exports = (client, { d: data }) => {
5
6
  /**
6
7
  * Emitted whenever client user receive interaction.showModal()