djs-selfbot-v13 3.1.6 → 3.1.7

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 (148) hide show
  1. package/README.md +31 -16
  2. package/package.json +15 -8
  3. package/src/client/BaseClient.js +3 -2
  4. package/src/client/Client.js +539 -187
  5. package/src/client/actions/Action.js +13 -18
  6. package/src/client/actions/ActionsManager.js +1 -7
  7. package/src/client/actions/AutoModerationActionExecution.js +0 -1
  8. package/src/client/actions/AutoModerationRuleCreate.js +0 -1
  9. package/src/client/actions/AutoModerationRuleDelete.js +0 -1
  10. package/src/client/actions/AutoModerationRuleUpdate.js +0 -1
  11. package/src/client/actions/InteractionCreate.js +115 -0
  12. package/src/client/actions/MessageCreate.js +4 -0
  13. package/src/client/actions/PresenceUpdate.js +16 -17
  14. package/src/client/websocket/WebSocketManager.js +31 -11
  15. package/src/client/websocket/WebSocketShard.js +38 -39
  16. package/src/client/websocket/handlers/APPLICATION_COMMAND_AUTOCOMPLETE_RESPONSE.js +23 -0
  17. package/src/client/websocket/handlers/CALL_CREATE.js +3 -3
  18. package/src/client/websocket/handlers/CALL_DELETE.js +2 -2
  19. package/src/client/websocket/handlers/CALL_UPDATE.js +2 -2
  20. package/src/client/websocket/handlers/CHANNEL_RECIPIENT_ADD.js +13 -16
  21. package/src/client/websocket/handlers/CHANNEL_RECIPIENT_REMOVE.js +11 -11
  22. package/src/client/websocket/handlers/GUILD_APPLICATION_COMMANDS_UPDATE.js +11 -0
  23. package/src/client/websocket/handlers/GUILD_CREATE.js +0 -7
  24. package/src/client/websocket/handlers/GUILD_MEMBER_LIST_UPDATE.js +55 -0
  25. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUNDS_UPDATE.js +0 -0
  26. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_CREATE.js +0 -0
  27. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_DELETE.js +0 -0
  28. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_UPDATE.js +0 -0
  29. package/src/client/websocket/handlers/INTERACTION_CREATE.js +16 -0
  30. package/src/client/websocket/handlers/INTERACTION_FAILURE.js +18 -0
  31. package/src/client/websocket/handlers/INTERACTION_MODAL_CREATE.js +0 -1
  32. package/src/client/websocket/handlers/INTERACTION_SUCCESS.js +30 -0
  33. package/src/client/websocket/handlers/MESSAGE_ACK.js +16 -0
  34. package/src/client/websocket/handlers/READY.js +137 -47
  35. package/src/client/websocket/handlers/RELATIONSHIP_ADD.js +5 -7
  36. package/src/client/websocket/handlers/RELATIONSHIP_REMOVE.js +4 -6
  37. package/src/client/websocket/handlers/RELATIONSHIP_UPDATE.js +9 -32
  38. package/src/client/websocket/handlers/SOUNDBOARD_SOUNDS.js +0 -0
  39. package/src/client/websocket/handlers/USER_GUILD_SETTINGS_UPDATE.js +8 -2
  40. package/src/client/websocket/handlers/USER_NOTE_UPDATE.js +1 -1
  41. package/src/client/websocket/handlers/USER_SETTINGS_UPDATE.js +5 -1
  42. package/src/client/websocket/handlers/VOICE_CHANNEL_EFFECT_SEND.js +0 -0
  43. package/src/client/websocket/handlers/index.js +20 -15
  44. package/src/errors/Messages.js +69 -24
  45. package/src/index.js +43 -12
  46. package/src/managers/ApplicationCommandManager.js +12 -9
  47. package/src/managers/ApplicationCommandPermissionsManager.js +11 -3
  48. package/src/managers/ChannelManager.js +4 -2
  49. package/src/managers/ClientUserSettingManager.js +279 -161
  50. package/src/managers/DeveloperPortalManager.js +104 -0
  51. package/src/managers/GuildApplicationCommandManager.js +28 -0
  52. package/src/managers/GuildBanManager.js +1 -1
  53. package/src/managers/GuildChannelManager.js +0 -2
  54. package/src/managers/GuildFolderManager.js +24 -0
  55. package/src/managers/GuildForumThreadManager.js +28 -22
  56. package/src/managers/GuildMemberManager.js +216 -40
  57. package/src/managers/GuildSettingManager.js +15 -22
  58. package/src/managers/MessageManager.js +44 -42
  59. package/src/managers/PermissionOverwriteManager.js +1 -1
  60. package/src/managers/ReactionUserManager.js +5 -5
  61. package/src/managers/RelationshipManager.js +74 -81
  62. package/src/managers/SessionManager.js +57 -0
  63. package/src/managers/ThreadManager.js +45 -12
  64. package/src/managers/ThreadMemberManager.js +1 -1
  65. package/src/managers/UserManager.js +10 -6
  66. package/src/rest/APIRequest.js +20 -42
  67. package/src/rest/CaptchaSolver.js +132 -0
  68. package/src/rest/DiscordAPIError.js +16 -17
  69. package/src/rest/RESTManager.js +21 -1
  70. package/src/rest/RequestHandler.js +21 -35
  71. package/src/structures/ApplicationCommand.js +456 -19
  72. package/src/structures/ApplicationRoleConnectionMetadata.js +0 -3
  73. package/src/structures/AutoModerationRule.js +5 -5
  74. package/src/structures/AutocompleteInteraction.js +0 -1
  75. package/src/structures/BaseGuildTextChannel.js +12 -10
  76. package/src/structures/BaseGuildVoiceChannel.js +18 -16
  77. package/src/structures/{CallState.js → Call.js} +12 -17
  78. package/src/structures/CategoryChannel.js +0 -2
  79. package/src/structures/Channel.js +3 -2
  80. package/src/structures/ClientApplication.js +204 -0
  81. package/src/structures/ClientPresence.js +8 -12
  82. package/src/structures/ClientUser.js +336 -117
  83. package/src/structures/ContextMenuInteraction.js +1 -1
  84. package/src/structures/DMChannel.js +92 -29
  85. package/src/structures/DeveloperPortalApplication.js +520 -0
  86. package/src/structures/ForumChannel.js +10 -0
  87. package/src/structures/Guild.js +271 -135
  88. package/src/structures/GuildAuditLogs.js +5 -0
  89. package/src/structures/GuildChannel.js +2 -16
  90. package/src/structures/GuildFolder.js +75 -0
  91. package/src/structures/GuildMember.js +145 -27
  92. package/src/structures/Interaction.js +62 -1
  93. package/src/structures/InteractionResponse.js +114 -0
  94. package/src/structures/Invite.js +52 -35
  95. package/src/structures/Message.js +202 -222
  96. package/src/structures/MessageAttachment.js +0 -11
  97. package/src/structures/MessageButton.js +67 -1
  98. package/src/structures/MessageEmbed.js +1 -1
  99. package/src/structures/MessageMentions.js +2 -3
  100. package/src/structures/MessagePayload.js +46 -4
  101. package/src/structures/MessageReaction.js +1 -1
  102. package/src/structures/MessageSelectMenu.js +252 -1
  103. package/src/structures/Modal.js +180 -75
  104. package/src/structures/PartialGroupDMChannel.js +433 -0
  105. package/src/structures/Presence.js +2 -2
  106. package/src/structures/RichPresence.js +34 -14
  107. package/src/structures/Role.js +2 -18
  108. package/src/structures/SelectMenuInteraction.js +151 -2
  109. package/src/structures/Session.js +81 -0
  110. package/src/structures/Team.js +49 -0
  111. package/src/structures/TextInputComponent.js +70 -0
  112. package/src/structures/ThreadChannel.js +19 -0
  113. package/src/structures/User.js +345 -117
  114. package/src/structures/UserContextMenuInteraction.js +2 -2
  115. package/src/structures/VoiceState.js +39 -74
  116. package/src/structures/WebEmbed.js +52 -38
  117. package/src/structures/Webhook.js +11 -17
  118. package/src/structures/interfaces/Application.js +23 -146
  119. package/src/structures/interfaces/TextBasedChannel.js +256 -411
  120. package/src/util/ApplicationFlags.js +1 -1
  121. package/src/util/Constants.js +284 -106
  122. package/src/util/Formatters.js +2 -16
  123. package/src/util/LimitedCollection.js +1 -1
  124. package/src/util/Options.js +68 -48
  125. package/src/util/Permissions.js +0 -5
  126. package/src/util/PurchasedFlags.js +0 -2
  127. package/src/util/RemoteAuth.js +356 -221
  128. package/src/util/Sweepers.js +1 -1
  129. package/src/util/Util.js +36 -76
  130. package/src/util/Voice.js +1456 -0
  131. package/src/util/arRPC/index.js +229 -0
  132. package/src/util/arRPC/process/detectable.json +1 -0
  133. package/src/util/arRPC/process/index.js +102 -0
  134. package/src/util/arRPC/process/native/index.js +5 -0
  135. package/src/util/arRPC/process/native/linux.js +37 -0
  136. package/src/util/arRPC/process/native/win32.js +25 -0
  137. package/src/util/arRPC/transports/ipc.js +281 -0
  138. package/src/util/arRPC/transports/websocket.js +128 -0
  139. package/typings/enums.d.ts +73 -18
  140. package/typings/index.d.ts +1249 -897
  141. package/typings/rawDataTypes.d.ts +9 -68
  142. package/src/client/websocket/handlers/USER_REQUIRED_ACTION_UPDATE.js +0 -78
  143. package/src/client/websocket/handlers/VOICE_CHANNEL_STATUS_UPDATE.js +0 -12
  144. package/src/managers/UserNoteManager.js +0 -53
  145. package/src/structures/GroupDMChannel.js +0 -387
  146. package/src/util/AttachmentFlags.js +0 -38
  147. package/src/util/InviteFlags.js +0 -29
  148. package/src/util/RoleFlags.js +0 -37
@@ -32,31 +32,26 @@ class GenericAction {
32
32
  }
33
33
 
34
34
  getChannel(data) {
35
- const payloadData = {};
36
35
  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
-
50
36
  return (
51
- data[this.client.actions.injectedChannel] ??
52
- this.getPayload(payloadData, this.client.channels, id, PartialTypes.CHANNEL)
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
+ )
53
48
  );
54
49
  }
55
50
 
56
51
  getMessage(data, channel, cache) {
57
52
  const id = data.message_id ?? data.id;
58
53
  return (
59
- data[this.client.actions.injectedMessage] ??
54
+ data.message ??
60
55
  this.getPayload(
61
56
  {
62
57
  id,
@@ -91,7 +86,7 @@ class GenericAction {
91
86
 
92
87
  getUser(data) {
93
88
  const id = data.user_id;
94
- return data[this.client.actions.injectedUser] ?? this.getPayload({ id }, this.client.users, id, PartialTypes.USER);
89
+ return data.user ?? this.getPayload({ id }, this.client.users, id, PartialTypes.USER);
95
90
  }
96
91
 
97
92
  getUserFromMember(data) {
@@ -4,13 +4,6 @@ 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
-
14
7
  this.register(require('./ApplicationCommandPermissionsUpdate'));
15
8
  this.register(require('./AutoModerationActionExecution'));
16
9
  this.register(require('./AutoModerationRuleCreate'));
@@ -45,6 +38,7 @@ class ActionsManager {
45
38
  this.register(require('./GuildStickerUpdate'));
46
39
  this.register(require('./GuildStickersUpdate'));
47
40
  this.register(require('./GuildUpdate'));
41
+ this.register(require('./InteractionCreate'));
48
42
  this.register(require('./InviteCreate'));
49
43
  this.register(require('./InviteDelete'));
50
44
  this.register(require('./MessageCreate'));
@@ -15,7 +15,6 @@ 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.
19
18
  */
20
19
  client.emit(Events.AUTO_MODERATION_ACTION_EXECUTION, new AutoModerationActionExecution(data, guild));
21
20
  }
@@ -16,7 +16,6 @@ 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.
20
19
  */
21
20
  client.emit(Events.AUTO_MODERATION_RULE_CREATE, autoModerationRule);
22
21
  }
@@ -19,7 +19,6 @@ 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.
23
22
  */
24
23
  client.emit(Events.AUTO_MODERATION_RULE_DELETE, autoModerationRule);
25
24
  }
@@ -18,7 +18,6 @@ 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.
22
21
  */
23
22
  client.emit(Events.AUTO_MODERATION_RULE_UPDATE, oldAutoModerationRule, newAutoModerationRule);
24
23
  }
@@ -0,0 +1,115 @@
1
+ 'use strict';
2
+
3
+ const process = require('node:process');
4
+ const Action = require('./Action');
5
+ const AutocompleteInteraction = require('../../structures/AutocompleteInteraction');
6
+ const ButtonInteraction = require('../../structures/ButtonInteraction');
7
+ const CommandInteraction = require('../../structures/CommandInteraction');
8
+ const MessageContextMenuInteraction = require('../../structures/MessageContextMenuInteraction');
9
+ const ModalSubmitInteraction = require('../../structures/ModalSubmitInteraction');
10
+ const {
11
+ ChannelSelectInteraction,
12
+ MentionableSelectInteraction,
13
+ RoleSelectInteraction,
14
+ SelectMenuInteraction,
15
+ UserSelectInteraction,
16
+ } = require('../../structures/SelectMenuInteraction');
17
+ const UserContextMenuInteraction = require('../../structures/UserContextMenuInteraction');
18
+ const { Events, InteractionTypes, MessageComponentTypes, ApplicationCommandTypes } = require('../../util/Constants');
19
+
20
+ let deprecationEmitted = false;
21
+
22
+ class InteractionCreateAction extends Action {
23
+ handle(data) {
24
+ const client = this.client;
25
+
26
+ // Resolve and cache partial channels for Interaction#channel getter
27
+ const channel = this.getChannel(data);
28
+ // Do not emit this for interactions that cache messages that are non-text-based.
29
+ let InteractionType;
30
+ switch (data.type) {
31
+ case InteractionTypes.APPLICATION_COMMAND:
32
+ switch (data.data.type) {
33
+ case ApplicationCommandTypes.CHAT_INPUT:
34
+ InteractionType = CommandInteraction;
35
+ break;
36
+ case ApplicationCommandTypes.USER:
37
+ InteractionType = UserContextMenuInteraction;
38
+ break;
39
+ case ApplicationCommandTypes.MESSAGE:
40
+ InteractionType = MessageContextMenuInteraction;
41
+ break;
42
+ default:
43
+ client.emit(
44
+ Events.DEBUG,
45
+ `[INTERACTION] Received application command interaction with unknown type: ${data.data.type}`,
46
+ );
47
+ return;
48
+ }
49
+ break;
50
+ case InteractionTypes.MESSAGE_COMPONENT:
51
+ if (channel && !channel.isText()) return;
52
+ switch (data.data.component_type) {
53
+ case MessageComponentTypes.BUTTON:
54
+ InteractionType = ButtonInteraction;
55
+ break;
56
+ case MessageComponentTypes.STRING_SELECT:
57
+ InteractionType = SelectMenuInteraction;
58
+ break;
59
+ case MessageComponentTypes.CHANNEL_SELECT:
60
+ InteractionType = ChannelSelectInteraction;
61
+ break;
62
+ case MessageComponentTypes.MENTIONABLE_SELECT:
63
+ InteractionType = MentionableSelectInteraction;
64
+ break;
65
+ case MessageComponentTypes.ROLE_SELECT:
66
+ InteractionType = RoleSelectInteraction;
67
+ break;
68
+ case MessageComponentTypes.USER_SELECT:
69
+ InteractionType = UserSelectInteraction;
70
+ break;
71
+ default:
72
+ client.emit(
73
+ Events.DEBUG,
74
+ `[INTERACTION] Received component interaction with unknown type: ${data.data.component_type}`,
75
+ );
76
+ return;
77
+ }
78
+ break;
79
+ case InteractionTypes.APPLICATION_COMMAND_AUTOCOMPLETE:
80
+ InteractionType = AutocompleteInteraction;
81
+ break;
82
+ case InteractionTypes.MODAL_SUBMIT:
83
+ InteractionType = ModalSubmitInteraction;
84
+ break;
85
+ default:
86
+ client.emit(
87
+ Events.DEBUG,
88
+ `[INTERACTION] Received [BOT] / Send (Selfbot) interactionID ${data.id} with unknown type: ${data.type}`,
89
+ );
90
+ return;
91
+ }
92
+
93
+ const interaction = new InteractionType(client, data);
94
+
95
+ /**
96
+ * Emitted when an interaction is created.
97
+ * @event Client#interactionCreate
98
+ * @param {InteractionResponseBody | Interaction} interaction The interaction which was created.
99
+ */
100
+ client.emit(Events.INTERACTION_CREATE, interaction);
101
+
102
+ /**
103
+ * Emitted when an interaction is created.
104
+ * @event Client#interaction
105
+ * @param {Interaction} interaction The interaction which was created
106
+ * @deprecated Use {@link Client#event:interactionCreate} instead
107
+ */
108
+ if (client.emit('interaction', interaction) && !deprecationEmitted) {
109
+ deprecationEmitted = true;
110
+ process.emitWarning('The interaction event is deprecated. Use interactionCreate instead', 'DeprecationWarning');
111
+ }
112
+ }
113
+ }
114
+
115
+ module.exports = InteractionCreateAction;
@@ -18,6 +18,10 @@ 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
+
21
25
  /**
22
26
  * Emitted whenever a message is created.
23
27
  * @event Client#messageCreate
@@ -13,9 +13,11 @@ class PresenceUpdateAction extends Action {
13
13
  if (!user._equals(data.user)) this.client.actions.UserUpdate.handle(data.user);
14
14
  }
15
15
 
16
- const guild = this.client.guilds.cache.get(data.guild_id);
17
-
18
- if (guild) {
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;
19
21
  let member = guild.members.cache.get(user.id);
20
22
  if (!member && data.status !== 'offline') {
21
23
  member = guild.members._add({
@@ -25,20 +27,17 @@ class PresenceUpdateAction extends Action {
25
27
  });
26
28
  this.client.emit(Events.GUILD_MEMBER_AVAILABLE, member);
27
29
  }
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);
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
+ }
42
41
  }
43
42
  }
44
43
  }
@@ -126,15 +126,36 @@ class WebSocketManager extends EventEmitter {
126
126
  * @private
127
127
  */
128
128
  async connect() {
129
- let gatewayURL = 'wss://gateway.discord.gg';
130
- await this.client.api.gateway
131
- .get({ auth: false })
132
- .then(r => (gatewayURL = r.url))
133
- .catch(() => {});
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
+ */
134
141
 
135
- const total = Infinity;
136
- const remaining = Infinity;
142
+ 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;
137
152
  const recommendedShards = 1;
153
+ const sessionStartLimit = {
154
+ total: Infinity,
155
+ remaining: Infinity,
156
+ };
157
+
158
+ const { total, remaining } = sessionStartLimit;
138
159
 
139
160
  this.debug(`Fetched Gateway Information
140
161
  URL: ${gatewayURL}
@@ -273,7 +294,7 @@ class WebSocketManager extends EventEmitter {
273
294
  } catch (error) {
274
295
  this.debug(`Couldn't reconnect or fetch information about the gateway. ${error}`);
275
296
  if (error.httpStatus !== 401) {
276
- this.debug(`Possible network error occurred. Retrying in 5s...`);
297
+ this.debug('Possible network error occurred. Retrying in 5s...');
277
298
  await sleep(5_000);
278
299
  this.reconnecting = false;
279
300
  return this.reconnect();
@@ -347,12 +368,11 @@ class WebSocketManager extends EventEmitter {
347
368
  /**
348
369
  * Emitted whenever a packet isn't handled.
349
370
  * @event Client#unhandledPacket
350
- * @param {Object} packet The packet (t: EVENT_NAME, d: any)
351
- * @param {Number} shard The shard that received the packet (Shard 0)
371
+ * @param {Object} packet The packet (t: Event name, d: Data)
372
+ * @param {Number} shard The shard that received the packet (Auto = 0)
352
373
  */
353
374
  this.client.emit(Events.UNHANDLED_PACKET, packet, shard);
354
375
  }
355
-
356
376
  return true;
357
377
  }
358
378
 
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  const EventEmitter = require('node:events');
4
- const http = require('node:http');
5
4
  const { setTimeout, setInterval, clearTimeout } = require('node:timers');
6
5
  const WebSocket = require('../../WebSocket');
7
6
  const { Status, Events, ShardEvents, Opcodes, WSEvents, WSCodes } = require('../../util/Constants');
@@ -18,7 +17,6 @@ try {
18
17
 
19
18
  /**
20
19
  * Represents a Shard's WebSocket connection
21
- * @extends {EventEmitter}
22
20
  */
23
21
  class WebSocketShard extends EventEmitter {
24
22
  constructor(manager, id) {
@@ -36,13 +34,6 @@ class WebSocketShard extends EventEmitter {
36
34
  */
37
35
  this.id = id;
38
36
 
39
- /**
40
- * The resume URL for this shard
41
- * @type {?string}
42
- * @private
43
- */
44
- this.resumeURL = null;
45
-
46
37
  /**
47
38
  * The current status of the shard
48
39
  * @type {Status}
@@ -70,6 +61,13 @@ class WebSocketShard extends EventEmitter {
70
61
  */
71
62
  this.sessionId = null;
72
63
 
64
+ /**
65
+ * URL to use when resuming
66
+ * @type {?string}
67
+ * @private
68
+ */
69
+ this.resumeURL = null;
70
+
73
71
  /**
74
72
  * The previous heartbeat ping of the shard
75
73
  * @type {number}
@@ -201,12 +199,12 @@ class WebSocketShard extends EventEmitter {
201
199
  connect() {
202
200
  const { client } = this.manager;
203
201
 
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
-
210
208
  return new Promise((resolve, reject) => {
211
209
  const cleanup = () => {
212
210
  this.removeListener(ShardEvents.CLOSE, onClose);
@@ -272,7 +270,7 @@ class WebSocketShard extends EventEmitter {
272
270
  Version : ${client.options.ws.version}
273
271
  Encoding : ${WebSocket.encoding}
274
272
  Compression: ${zlib ? 'zlib-stream' : 'none'}
275
- Agent : ${client.options.ws.agent instanceof http.Agent}`,
273
+ Proxy : ${client.options.proxy || 'none'}`,
276
274
  );
277
275
 
278
276
  this.status = this.status === Status.DISCONNECTED ? Status.RECONNECTING : Status.CONNECTING;
@@ -280,11 +278,14 @@ class WebSocketShard extends EventEmitter {
280
278
  this.setWsCloseTimeout(-1);
281
279
  this.connectedAt = Date.now();
282
280
 
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
+ }
283
287
  // Adding a handshake timeout to just make sure no zombie connection appears.
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
- }));
288
+ const ws = (this.connection = WebSocket.create(gateway, wsQuery, args));
288
289
  ws.onopen = this.onOpen.bind(this);
289
290
  ws.onmessage = this.onMessage.bind(this);
290
291
  ws.onerror = this.onError.bind(this);
@@ -432,11 +433,11 @@ class WebSocketShard extends EventEmitter {
432
433
  */
433
434
  this.emit(ShardEvents.READY);
434
435
 
435
- this.resumeURL = packet.d.resume_gateway_url;
436
436
  this.sessionId = packet.d.session_id;
437
+ this.resumeURL = packet.d.resume_gateway_url;
437
438
  this.expectedGuilds = new Set(packet.d.guilds.filter(d => d?.unavailable == true).map(d => d.id));
438
439
  this.status = Status.WAITING_FOR_GUILDS;
439
- this.debug(`[READY] Session ${this.sessionId} | Resume url ${this.resumeURL}.`);
440
+ this.debug(`[READY] Session ${this.sessionId} | ResumeURL ${this.resumeURL}`);
440
441
  this.lastHeartbeatAcked = true;
441
442
  this.sendHeartbeat('ReadyHeartbeat');
442
443
  break;
@@ -537,23 +538,21 @@ class WebSocketShard extends EventEmitter {
537
538
 
538
539
  const { waitGuildTimeout } = this.manager.client.options;
539
540
 
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
- );
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
+ );
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
- },
555
- hasGuildsIntent ? waitGuildTimeout : 0,
556
- ).unref();
553
+ this.emit(ShardEvents.ALL_READY, this.expectedGuilds);
554
+ // }, hasGuildsIntent && waitGuildTimeout).unref();
555
+ }, waitGuildTimeout).unref();
557
556
  }
558
557
 
559
558
  /**
@@ -594,7 +593,6 @@ class WebSocketShard extends EventEmitter {
594
593
  }
595
594
  this.wsCloseTimeout = setTimeout(() => {
596
595
  this.setWsCloseTimeout(-1);
597
-
598
596
  // Check if close event was emitted.
599
597
  if (this.closeEmitted) {
600
598
  this.debug(`[WebSocket] close was already emitted, assuming the connection was closed properly.`);
@@ -658,6 +656,7 @@ class WebSocketShard extends EventEmitter {
658
656
  Sequence : ${this.sequence}
659
657
  Connection State: ${this.connection ? CONNECTION_STATE[this.connection.readyState] : 'No Connection??'}`,
660
658
  );
659
+
661
660
  this.destroy({ reset: true, closeCode: 4009 });
662
661
  return;
663
662
  }
@@ -701,24 +700,25 @@ class WebSocketShard extends EventEmitter {
701
700
 
702
701
  this.status = Status.IDENTIFYING;
703
702
 
704
- // Patch something
705
703
  Object.keys(client.options.ws.properties)
706
704
  .filter(k => k.startsWith('$'))
707
705
  .forEach(k => {
708
706
  client.options.ws.properties[k.slice(1)] = client.options.ws.properties[k];
709
707
  delete client.options.ws.properties[k];
710
708
  });
711
-
712
- // Clone the identify payload and assign the token and shard info
713
709
  const d = {
710
+ presence: client.options.presence,
714
711
  ...client.options.ws,
715
712
  token: client.token,
716
713
  };
717
714
 
718
715
  delete d.version;
719
- delete d.agent;
720
716
 
721
- this.debug(`[IDENTIFY] Shard ${this.id}`);
717
+ this.debug(
718
+ `[IDENTIFY] Shard ${this.id}/${client.options.shardCount} with intents: ${Intents.resolve(
719
+ client.options.intents,
720
+ )} 😊`,
721
+ );
722
722
  this.send({ op: Opcodes.IDENTIFY, d }, true);
723
723
  }
724
724
 
@@ -815,7 +815,6 @@ class WebSocketShard extends EventEmitter {
815
815
  // Step 0: Remove all timers
816
816
  this.setHeartbeatTimer(-1);
817
817
  this.setHelloTimeout(-1);
818
-
819
818
  this.debug(
820
819
  `[WebSocket] Destroy: Attempting to close the WebSocket. | WS State: ${
821
820
  CONNECTION_STATE[this.connection?.readyState ?? WebSocket.CLOSED]
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ const { Events } = require('../../../util/Constants');
4
+
5
+ module.exports = (client, { d: data }) => {
6
+ /**
7
+ * @typedef {object} AutocompleteResponseChoice
8
+ * @property {string} name The name of the choice
9
+ * @property {string} value The value of the choice
10
+ */
11
+ /**
12
+ * @typedef {object} AutocompleteResponse
13
+ * @property {Snowflake} [nonce] Snowflake of the data
14
+ * @property {Array<AutocompleteResponseChoice>} [choices] Array of choices
15
+ */
16
+ /**
17
+ * Emitted when receiving a response from Discord
18
+ * @event Client#applicationCommandAutocompleteResponse
19
+ * @param {AutocompleteResponse} data Data
20
+ * @deprecated Test only
21
+ */
22
+ client.emit(Events.APPLICATION_COMMAND_AUTOCOMPLETE_RESPONSE, data);
23
+ };
@@ -1,5 +1,5 @@
1
1
  'use strict';
2
- const CallState = require('../../../structures/CallState');
2
+ const Call = require('../../../structures/Call');
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 {CallState} call Call
11
+ * @param {Call} call Call
12
12
  */
13
- client.emit(Events.CALL_CREATE, new CallState(client, packet.d));
13
+ client.emit(Events.CALL_CREATE, new Call(client, packet.d));
14
14
  };
@@ -1,5 +1,5 @@
1
1
  'use strict';
2
- const CallState = require('../../../structures/CallState');
2
+ const Call = require('../../../structures/Call');
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 CallState(client, packet.d));
10
+ client.emit(Events.CALL_DELETE, new Call(client, packet.d));
11
11
  };
@@ -1,5 +1,5 @@
1
1
  'use strict';
2
- const CallState = require('../../../structures/CallState');
2
+ const Call = require('../../../structures/Call');
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 CallState(client, packet.d));
10
+ client.emit(Events.CALL_UPDATE, new Call(client, packet.d));
11
11
  };
@@ -1,19 +1,16 @@
1
1
  'use strict';
2
- const { Events, Status } = require('../../../util/Constants');
3
- module.exports = (client, packet, shard) => {
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
+ */
4
10
  const channel = client.channels.cache.get(packet.d.channel_id);
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
- }
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);
19
16
  };