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
@@ -3,6 +3,7 @@
3
3
  const { Buffer } = require('node:buffer');
4
4
  const BaseMessageComponent = require('./BaseMessageComponent');
5
5
  const MessageEmbed = require('./MessageEmbed');
6
+ const WebEmbed = require('./WebEmbed');
6
7
  const { RangeError } = require('../errors');
7
8
  const ActivityFlags = require('../util/ActivityFlags');
8
9
  const DataResolver = require('../util/DataResolver');
@@ -41,6 +42,7 @@ class MessagePayload {
41
42
  * @property {Buffer|string|Stream} attachment The original attachment that generated this file
42
43
  * @property {string} name The name of this file
43
44
  * @property {Buffer|Stream} file The file to be sent to the API
45
+ * @extends {APIAttachment}
44
46
  */
45
47
 
46
48
  /**
@@ -50,6 +52,15 @@ class MessagePayload {
50
52
  this.files = null;
51
53
  }
52
54
 
55
+ /**
56
+ * Whether or not using new API to upload files
57
+ * @type {boolean}
58
+ * @readonly
59
+ */
60
+ get usingNewAttachmentAPI() {
61
+ return Boolean(this.options?.usingNewAttachmentAPI);
62
+ }
63
+
53
64
  /**
54
65
  * Whether or not the target is a {@link Webhook} or a {@link WebhookClient}
55
66
  * @type {boolean}
@@ -122,12 +133,12 @@ class MessagePayload {
122
133
  * Resolves data.
123
134
  * @returns {MessagePayload}
124
135
  */
125
- resolveData() {
136
+ async resolveData() {
126
137
  if (this.data) return this;
127
138
  const isInteraction = this.isInteraction;
128
139
  const isWebhook = this.isWebhook;
129
140
 
130
- const content = this.makeContent();
141
+ let content = this.makeContent();
131
142
  const tts = Boolean(this.options.tts);
132
143
 
133
144
  let nonce;
@@ -197,6 +208,37 @@ class MessagePayload {
197
208
  this.options.attachments = attachments;
198
209
  }
199
210
 
211
+ if (this.options.embeds) {
212
+ if (!Array.isArray(this.options.embeds)) {
213
+ this.options.embeds = [this.options.embeds];
214
+ }
215
+
216
+ const webembeds = this.options.embeds.filter(e => e instanceof WebEmbed);
217
+ this.options.embeds = this.options.embeds.filter(e => !(e instanceof WebEmbed));
218
+
219
+ if (webembeds.length > 0) {
220
+ if (!content) content = '';
221
+ // Add hidden embed link
222
+ content += `\n${WebEmbed.hiddenEmbed} \n`;
223
+ if (webembeds.length > 1) {
224
+ console.warn('[WARN] Multiple webembeds are not supported, this will be ignored.');
225
+ }
226
+ // Const embed = webembeds[0];
227
+ for (const webE of webembeds) {
228
+ const data = await webE.toMessage();
229
+ content += `\n${data}`;
230
+ }
231
+ }
232
+ // Check content
233
+ if (typeof content == 'string' && content.length > 2000) {
234
+ console.warn('[WARN] Content is longer than 2000 characters.');
235
+ }
236
+ if (typeof content == 'string' && content.length > 4000) {
237
+ // Max length if user has nitro boost
238
+ throw new RangeError('MESSAGE_EMBED_LINK_LENGTH');
239
+ }
240
+ }
241
+
200
242
  // Activity
201
243
  let activity;
202
244
  if (
@@ -205,7 +247,7 @@ class MessagePayload {
205
247
  this.options.activity.type
206
248
  ) {
207
249
  const type = ActivityFlags.resolve(this.options.activity.type);
208
- const sessionId = this.target.client.sessionId;
250
+ const sessionId = this.target.client.session_id;
209
251
  const partyId = this.options.activity.partyId;
210
252
  activity = {
211
253
  type,
@@ -306,7 +348,7 @@ module.exports = MessagePayload;
306
348
 
307
349
  /**
308
350
  * A target for a message.
309
- * @typedef {TextBasedChannels|User|GuildMember|Webhook|WebhookClient|Interaction|InteractionWebhook|
351
+ * @typedef {TextBasedChannels|DMChannel|User|GuildMember|Webhook|WebhookClient|Interaction|InteractionWebhook|
310
352
  * Message|MessageManager} MessageTarget
311
353
  */
312
354
 
@@ -31,7 +31,7 @@ class MessageReaction {
31
31
  this.me = data.me || data.me_burst;
32
32
 
33
33
  /**
34
- * Is super reaction
34
+ * Super reaction
35
35
  * @type {boolean}
36
36
  */
37
37
  this.isBurst = Boolean(data.me_burst || data.burst);
@@ -1,7 +1,16 @@
1
1
  'use strict';
2
2
 
3
+ const { setTimeout } = require('node:timers');
3
4
  const BaseMessageComponent = require('./BaseMessageComponent');
4
- const { ChannelTypes, MessageComponentTypes } = require('../util/Constants');
5
+ const {
6
+ ChannelTypes,
7
+ MessageComponentTypes,
8
+ SelectMenuComponentTypes,
9
+ InteractionTypes,
10
+ } = require('../util/Constants');
11
+ const SnowflakeUtil = require('../util/SnowflakeUtil');
12
+ const { lazy } = require('../util/Util');
13
+ const Message = lazy(() => require('./Message').Message);
5
14
  const Util = require('../util/Util');
6
15
 
7
16
  /**
@@ -94,6 +103,130 @@ class MessageSelectMenu extends BaseMessageComponent {
94
103
  ) ?? [];
95
104
  }
96
105
 
106
+ /**
107
+ * Adds the channel types to the select menu
108
+ * @param {...ChannelType[]} channelTypes Added channel types
109
+ * @returns {MessageSelectMenu}
110
+ */
111
+ addChannelTypes(...channelTypes) {
112
+ if (!channelTypes.every(channelType => ChannelTypes[channelType])) {
113
+ throw new TypeError('INVALID_TYPE', 'channelTypes', 'Rest<ChannelTypes[]>');
114
+ }
115
+ this.channelTypes.push(
116
+ ...channelTypes.map(channelType => (typeof channelType === 'string' ? channelType : ChannelTypes[channelType])),
117
+ );
118
+ return this;
119
+ }
120
+
121
+ /**
122
+ * Sets the channel types of the select menu
123
+ * @param {...ChannelType[]} channelTypes An array of new channel types
124
+ * @returns {MessageSelectMenu}
125
+ */
126
+ setChannelTypes(...channelTypes) {
127
+ if (!channelTypes.every(channelType => ChannelTypes[channelType])) {
128
+ throw new TypeError('INVALID_TYPE', 'channelTypes', 'Rest<ChannelTypes[]>');
129
+ }
130
+ this.channelTypes = channelTypes.map(channelType =>
131
+ typeof channelType === 'string' ? channelType : ChannelTypes[channelType],
132
+ );
133
+ return this;
134
+ }
135
+
136
+ /**
137
+ * Sets the custom id of this select menu
138
+ * @param {string} customId A unique string to be sent in the interaction when clicked
139
+ * @returns {MessageSelectMenu}
140
+ */
141
+ setCustomId(customId) {
142
+ this.customId = Util.verifyString(customId, RangeError, 'SELECT_MENU_CUSTOM_ID');
143
+ return this;
144
+ }
145
+
146
+ /**
147
+ * Sets the interactive status of the select menu
148
+ * @param {boolean} [disabled=true] Whether this select menu should be disabled
149
+ * @returns {MessageSelectMenu}
150
+ */
151
+ setDisabled(disabled = true) {
152
+ this.disabled = disabled;
153
+ return this;
154
+ }
155
+
156
+ /**
157
+ * Sets the maximum number of selections allowed for this select menu
158
+ * @param {number} maxValues Number of selections to be allowed
159
+ * @returns {MessageSelectMenu}
160
+ */
161
+ setMaxValues(maxValues) {
162
+ this.maxValues = maxValues;
163
+ return this;
164
+ }
165
+
166
+ /**
167
+ * Sets the minimum number of selections required for this select menu
168
+ * <info>This will default the maxValues to the number of options, unless manually set</info>
169
+ * @param {number} minValues Number of selections to be required
170
+ * @returns {MessageSelectMenu}
171
+ */
172
+ setMinValues(minValues) {
173
+ this.minValues = minValues;
174
+ return this;
175
+ }
176
+
177
+ /**
178
+ * Sets the placeholder of this select menu
179
+ * @param {string} placeholder Custom placeholder text to display when nothing is selected
180
+ * @returns {MessageSelectMenu}
181
+ */
182
+ setPlaceholder(placeholder) {
183
+ this.placeholder = Util.verifyString(placeholder, RangeError, 'SELECT_MENU_PLACEHOLDER');
184
+ return this;
185
+ }
186
+
187
+ /**
188
+ * Sets the type of the select menu
189
+ * @param {SelectMenuComponentType} type Type of the select menu
190
+ * @returns {MessageSelectMenu}
191
+ */
192
+ setType(type) {
193
+ if (!SelectMenuComponentTypes[type]) throw new TypeError('INVALID_TYPE', 'type', 'SelectMenuComponentType');
194
+ this.type = BaseMessageComponent.resolveType(type);
195
+ return this;
196
+ }
197
+
198
+ /**
199
+ * Adds options to the select menu.
200
+ * @param {...MessageSelectOptionData|MessageSelectOptionData[]} options The options to add
201
+ * @returns {MessageSelectMenu}
202
+ */
203
+ addOptions(...options) {
204
+ this.options.push(...this.constructor.normalizeOptions(options));
205
+ return this;
206
+ }
207
+
208
+ /**
209
+ * Sets the options of the select menu.
210
+ * @param {...MessageSelectOptionData|MessageSelectOptionData[]} options The options to set
211
+ * @returns {MessageSelectMenu}
212
+ */
213
+ setOptions(...options) {
214
+ this.spliceOptions(0, this.options.length, options);
215
+ return this;
216
+ }
217
+
218
+ /**
219
+ * Removes, replaces, and inserts options in the select menu.
220
+ * @param {number} index The index to start at
221
+ * @param {number} deleteCount The number of options to remove
222
+ * @param {...MessageSelectOptionData|MessageSelectOptionData[]} [options] The replacing option objects
223
+ * @returns {MessageSelectMenu}
224
+ */
225
+ spliceOptions(index, deleteCount, ...options) {
226
+ this.options.splice(index, deleteCount, ...this.constructor.normalizeOptions(...options));
227
+ return this;
228
+ }
229
+
97
230
  /**
98
231
  * Transforms the select menu into a plain object
99
232
  * @returns {APIMessageSelectMenu} The raw data of this select menu
@@ -135,6 +268,124 @@ class MessageSelectMenu extends BaseMessageComponent {
135
268
  static normalizeOptions(...options) {
136
269
  return options.flat(Infinity).map(option => this.normalizeOption(option));
137
270
  }
271
+
272
+ // Add
273
+ /**
274
+ * Mesage select menu
275
+ * @param {Message} message The message this select menu is for
276
+ * @param {Array<any>} values The values of the select menu
277
+ * @returns {Promise<InteractionResponse>}
278
+ */
279
+ async select(message, values) {
280
+ if (!(message instanceof Message())) throw new Error('[UNKNOWN_MESSAGE] Please pass a valid Message');
281
+ if (!Array.isArray(values)) throw new TypeError('[INVALID_VALUES] Please pass an array of values');
282
+ if (!this.customId || this.disabled) {
283
+ throw new Error('[INVALID_MENU] Menu does not contain Id or has been disabled');
284
+ } // Disabled or null customID
285
+ if (values.length < this.minValues) {
286
+ throw new RangeError(`[SELECT_MENU_MIN_VALUES] The minimum number of values is ${this.minValues}`);
287
+ }
288
+ if (values.length > this.maxValues) {
289
+ throw new RangeError(`[SELECT_MENU_MAX_VALUES] The maximum number of values is ${this.maxValues}`);
290
+ }
291
+ const parseValues = value => {
292
+ switch (this.type) {
293
+ case 'SELECT_MENU':
294
+ case 'STRING_SELECT': {
295
+ if (typeof value !== 'string') throw new TypeError('[INVALID_VALUE] Please pass a string value');
296
+ const value_ = this.options.find(obj => obj.value === value || obj.label === value);
297
+ if (!value_) throw new Error('[INVALID_VALUE] Please pass a valid value');
298
+ return value_.value;
299
+ }
300
+ case 'USER_SELECT': {
301
+ const userId = this.client.users.resolveId(value);
302
+ if (!userId) throw new Error('[INVALID_VALUE] Please pass a valid user');
303
+ return userId;
304
+ }
305
+ case 'ROLE_SELECT': {
306
+ const roleId = this.client.roles.resolveId(value);
307
+ if (!roleId) throw new Error('[INVALID_VALUE] Please pass a valid role');
308
+ return roleId;
309
+ }
310
+ case 'MENTIONABLE_SELECT': {
311
+ const mentionableId = this.client.users.resolveId(value) || this.client.roles.resolveId(value);
312
+ if (!mentionableId) throw new Error('[INVALID_VALUE] Please pass a valid mentionable');
313
+ return mentionableId;
314
+ }
315
+ case 'CHANNEL_SELECT': {
316
+ const channel = this.client.channels.resolve(value);
317
+ if (!channel) throw new Error('[INVALID_VALUE] Please pass a valid channel');
318
+ if (!this.channelTypes.includes(channel.type)) {
319
+ throw new Error(
320
+ `[INVALID_VALUE] Please pass a valid channel type (Got: ${channel.type}, allow: ${this.channelTypes.join(
321
+ ', ',
322
+ )})`,
323
+ );
324
+ }
325
+ return channel.id;
326
+ }
327
+ default: {
328
+ throw new Error(`[INVALID_TYPE] Please pass a valid select menu type (Got ${this.type})`);
329
+ }
330
+ }
331
+ };
332
+
333
+ const nonce = SnowflakeUtil.generate();
334
+ const data = {
335
+ type: InteractionTypes.MESSAGE_COMPONENT,
336
+ guild_id: message.guild?.id ?? null,
337
+ channel_id: message.channel.id,
338
+ message_id: message.id,
339
+ application_id: message.applicationId ?? message.author.id,
340
+ session_id: message.client.session_id,
341
+ message_flags: message.flags.bitfield,
342
+ data: {
343
+ component_type: MessageComponentTypes[this.type],
344
+ custom_id: this.customId,
345
+ type: MessageComponentTypes[this.type],
346
+ values: values?.length ? values.map(parseValues) : [],
347
+ },
348
+ nonce,
349
+ };
350
+
351
+ await message.client.api.interactions.post({
352
+ data,
353
+ });
354
+ message.client._interactionCache.set(nonce, {
355
+ channelId: message.channelId,
356
+ guildId: message.guildId,
357
+ metadata: data,
358
+ });
359
+ return new Promise((resolve, reject) => {
360
+ const handler = data => {
361
+ timeout.refresh();
362
+ if (data.metadata?.nonce !== nonce) return;
363
+ clearTimeout(timeout);
364
+ message.client.removeListener('interactionResponse', handler);
365
+ message.client.decrementMaxListeners();
366
+ if (data.status) {
367
+ resolve(data.metadata);
368
+ } else {
369
+ reject(
370
+ new Error('INTERACTION_ERROR', {
371
+ cause: data,
372
+ }),
373
+ );
374
+ }
375
+ };
376
+ const timeout = setTimeout(() => {
377
+ message.client.removeListener('interactionResponse', handler);
378
+ message.client.decrementMaxListeners();
379
+ reject(
380
+ new Error('INTERACTION_TIMEOUT', {
381
+ cause: data,
382
+ }),
383
+ );
384
+ }, message.client.options.interactionTimeout).unref();
385
+ message.client.incrementMaxListeners();
386
+ message.client.on('interactionResponse', handler);
387
+ });
388
+ }
138
389
  }
139
390
 
140
391
  module.exports = MessageSelectMenu;