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
@@ -1,17 +1,28 @@
1
1
  'use strict';
2
2
 
3
+ const { setTimeout } = require('node:timers');
4
+ const { findBestMatch } = require('string-similarity');
3
5
  const Base = require('./Base');
6
+ const MessagePayload = require('./MessagePayload');
4
7
  const ApplicationCommandPermissionsManager = require('../managers/ApplicationCommandPermissionsManager');
5
- const { ApplicationCommandOptionTypes, ApplicationCommandTypes, ChannelTypes } = require('../util/Constants');
8
+ const {
9
+ ApplicationCommandOptionTypes,
10
+ ApplicationCommandTypes,
11
+ ChannelTypes,
12
+ Events,
13
+ InteractionTypes,
14
+ } = require('../util/Constants');
6
15
  const Permissions = require('../util/Permissions');
7
16
  const SnowflakeUtil = require('../util/SnowflakeUtil');
17
+ const { lazy, getAttachments, uploadFile } = require('../util/Util');
18
+ const Message = lazy(() => require('../structures/Message').Message);
8
19
 
9
20
  /**
10
21
  * Represents an application command.
11
22
  * @extends {Base}
12
23
  */
13
24
  class ApplicationCommand extends Base {
14
- constructor(client, data, guild, guildId) {
25
+ constructor(client, data) {
15
26
  super(client);
16
27
 
17
28
  /**
@@ -26,24 +37,11 @@ class ApplicationCommand extends Base {
26
37
  */
27
38
  this.applicationId = data.application_id;
28
39
 
29
- /**
30
- * The guild this command is part of
31
- * @type {?Guild}
32
- */
33
- this.guild = guild ?? null;
34
-
35
- /**
36
- * The guild's id this command is part of, this may be non-null when `guild` is `null` if the command
37
- * was fetched from the `ApplicationCommandManager`
38
- * @type {?Snowflake}
39
- */
40
- this.guildId = guild?.id ?? guildId ?? null;
41
-
42
40
  /**
43
41
  * The manager for permissions of this command on its guild or arbitrary guilds when the command is global
44
42
  * @type {ApplicationCommandPermissionsManager}
45
43
  */
46
- this.permissions = new ApplicationCommandPermissionsManager(this);
44
+ this.permissions = new ApplicationCommandPermissionsManager(this, this.applicationId);
47
45
 
48
46
  /**
49
47
  * The type of this application command
@@ -51,10 +49,30 @@ class ApplicationCommand extends Base {
51
49
  */
52
50
  this.type = ApplicationCommandTypes[data.type];
53
51
 
52
+ this.user = client.users.cache.get(this.applicationId);
53
+
54
54
  this._patch(data);
55
55
  }
56
56
 
57
+ /**
58
+ * The guild this command is part of
59
+ * @type {?Guild}
60
+ * @readonly
61
+ */
62
+ get guild() {
63
+ return this.client.guilds.resolve(this.guildId);
64
+ }
65
+
57
66
  _patch(data) {
67
+ if ('guild_id' in data) {
68
+ /**
69
+ * The guild's id this command is part of, this may be non-null when `guild` is `null` if the command
70
+ * was fetched from the `ApplicationCommandManager`
71
+ * @type {?Snowflake}
72
+ */
73
+ this.guildId = data.guild_id ?? null;
74
+ }
75
+
58
76
  if ('name' in data) {
59
77
  /**
60
78
  * The name of this command
@@ -130,6 +148,7 @@ class ApplicationCommand extends Base {
130
148
  */
131
149
  this.defaultPermission = data.default_permission;
132
150
  }
151
+
133
152
  /* eslint-disable max-len */
134
153
 
135
154
  if ('default_member_permissions' in data) {
@@ -317,6 +336,7 @@ class ApplicationCommand extends Base {
317
336
  setDefaultPermission(defaultPermission = true) {
318
337
  return this.edit({ defaultPermission });
319
338
  }
339
+
320
340
  /* eslint-enable max-len */
321
341
 
322
342
  /**
@@ -371,7 +391,6 @@ class ApplicationCommand extends Base {
371
391
  equals(command, enforceOptionOrder = false) {
372
392
  // If given an id, check if the id matches
373
393
  if (command.id && this.id !== command.id) return false;
374
-
375
394
  let defaultMemberPermissions = null;
376
395
  let dmPermission = command.dmPermission ?? command.dm_permission;
377
396
 
@@ -385,7 +404,6 @@ class ApplicationCommand extends Base {
385
404
  defaultMemberPermissions =
386
405
  command.defaultMemberPermissions !== null ? new Permissions(command.defaultMemberPermissions).bitfield : null;
387
406
  }
388
-
389
407
  // Check top level parameters
390
408
  const commandType = typeof command.type === 'string' ? command.type : ApplicationCommandTypes[command.type];
391
409
  if (
@@ -428,7 +446,9 @@ class ApplicationCommand extends Base {
428
446
  const newOptions = new Map(options.map(option => [option.name, option]));
429
447
  for (const option of existing) {
430
448
  const foundOption = newOptions.get(option.name);
431
- if (!foundOption || !this._optionEquals(option, foundOption)) return false;
449
+ if (!foundOption || !this._optionEquals(option, foundOption)) {
450
+ return false;
451
+ }
432
452
  }
433
453
  return true;
434
454
  }
@@ -577,6 +597,423 @@ class ApplicationCommand extends Base {
577
597
  [maxLengthKey]: option.maxLength ?? option.max_length,
578
598
  };
579
599
  }
600
+ /**
601
+ * Send Slash command to channel
602
+ * @param {Message} message Discord Message
603
+ * @param {Array<string>} subCommandArray SubCommand Array
604
+ * @param {Array<any>} options The options to Slash Command
605
+ * @returns {Promise<InteractionResponse>}
606
+ */
607
+ // eslint-disable-next-line consistent-return
608
+ async sendSlashCommand(message, subCommandArray = [], options = []) {
609
+ // Todo: Refactor [Done]
610
+ const buildError = (type, value, array, msg) =>
611
+ new Error(`Invalid ${type}: ${value} ${msg}\nList of ${type}:\n${array}`);
612
+ // Check Options
613
+ if (!(message instanceof Message())) {
614
+ throw new TypeError('The message must be a Discord.Message');
615
+ }
616
+ if (!Array.isArray(options)) {
617
+ throw new TypeError('The options must be an array of strings');
618
+ }
619
+ if (this.type !== 'CHAT_INPUT') throw new Error('This command is not a chat input [/]');
620
+ const optionFormat = [];
621
+ const attachments = [];
622
+ const attachmentsBuffer = [];
623
+ const parseChoices = (list_choices, value) => {
624
+ if (value !== undefined) {
625
+ if (Array.isArray(list_choices) && list_choices.length) {
626
+ const choice = list_choices.find(c => c.name === value) || list_choices.find(c => c.value === value);
627
+ if (choice) {
628
+ return choice.value;
629
+ }
630
+ throw buildError(
631
+ 'choice',
632
+ value,
633
+ list_choices.map((c, i) => ` #${i + 1} Name: ${c.name} Value: ${c.value}`).join('\n'),
634
+ 'is not a valid choice for this option',
635
+ );
636
+ } else {
637
+ return value;
638
+ }
639
+ } else {
640
+ return undefined;
641
+ }
642
+ };
643
+ const parseOption = async (optionCommand, value) => {
644
+ const data = {
645
+ type: ApplicationCommandOptionTypes[optionCommand.type],
646
+ name: optionCommand.name,
647
+ };
648
+ if (value !== undefined) {
649
+ value = parseChoices(optionCommand.choices, value);
650
+ switch (optionCommand.type) {
651
+ case 'BOOLEAN': {
652
+ data.value = Boolean(value);
653
+ break;
654
+ }
655
+ case 'INTEGER': {
656
+ data.value = Number(value);
657
+ break;
658
+ }
659
+ case 'ATTACHMENT': {
660
+ data.value = await addDataFromAttachment(value, this.client);
661
+ break;
662
+ }
663
+ case 'SUB_COMMAND_GROUP': {
664
+ break;
665
+ }
666
+ default: {
667
+ if (optionCommand.autocomplete) {
668
+ let optionsBuild;
669
+ switch (subCommandArray.length) {
670
+ case 0: {
671
+ optionsBuild = [
672
+ ...optionFormat,
673
+ {
674
+ type: ApplicationCommandOptionTypes[optionCommand.type],
675
+ name: optionCommand.name,
676
+ value,
677
+ focused: true,
678
+ },
679
+ ];
680
+ break;
681
+ }
682
+ case 1: {
683
+ const subCommand = this.options.find(o => o.name == subCommandArray[0] && o.type == 'SUB_COMMAND');
684
+ optionsBuild = [
685
+ {
686
+ type: ApplicationCommandOptionTypes[subCommand.type],
687
+ name: subCommand.name,
688
+ options: [
689
+ ...optionFormat,
690
+ {
691
+ type: ApplicationCommandOptionTypes[optionCommand.type],
692
+ name: optionCommand.name,
693
+ value,
694
+ focused: true,
695
+ },
696
+ ],
697
+ },
698
+ ];
699
+ break;
700
+ }
701
+ case 2: {
702
+ const subGroup = this.options.find(
703
+ o => o.name == subCommandArray[0] && o.type == 'SUB_COMMAND_GROUP',
704
+ );
705
+ const subCommand = subGroup.options.find(
706
+ o => o.name == subCommandArray[1] && o.type == 'SUB_COMMAND',
707
+ );
708
+ optionsBuild = [
709
+ {
710
+ type: ApplicationCommandOptionTypes[subGroup.type],
711
+ name: subGroup.name,
712
+ options: [
713
+ {
714
+ type: ApplicationCommandOptionTypes[subCommand.type],
715
+ name: subCommand.name,
716
+ options: [
717
+ ...optionFormat,
718
+ {
719
+ type: ApplicationCommandOptionTypes[optionCommand.type],
720
+ name: optionCommand.name,
721
+ value,
722
+ focused: true,
723
+ },
724
+ ],
725
+ },
726
+ ],
727
+ },
728
+ ];
729
+ break;
730
+ }
731
+ }
732
+ const autoValue = await getAutoResponse(optionsBuild, value);
733
+ data.value = autoValue;
734
+ } else {
735
+ data.value = value;
736
+ }
737
+ }
738
+ }
739
+ optionFormat.push(data);
740
+ }
741
+ return optionFormat;
742
+ };
743
+ const parseSubCommand = async (subCommandName, options, subGroup) => {
744
+ const options_sub = subGroup ? subGroup.options : this.options;
745
+ const subCommand = options_sub.find(
746
+ o => (o.name == subCommandName || o.nameLocalized == subCommandName) && o.type == 'SUB_COMMAND',
747
+ );
748
+ if (!subCommand) {
749
+ throw buildError(
750
+ 'SubCommand',
751
+ subCommandName,
752
+ options_sub.map((o, i) => ` #${i + 1} Name: ${o.name}`).join('\n'),
753
+ 'is not a valid sub command',
754
+ );
755
+ }
756
+ const valueRequired = subCommand.options?.filter(o => o.required).length || 0;
757
+ for (let i = 0; i < options.length; i++) {
758
+ const optionInput = subCommand.options[i];
759
+ const value = options[i];
760
+ await parseOption(optionInput, value);
761
+ }
762
+ if (valueRequired > options.length) {
763
+ throw new Error(`Value required missing\nDebug:
764
+ Required: ${valueRequired} - Options: ${optionFormat.length}`);
765
+ }
766
+ return {
767
+ type: ApplicationCommandOptionTypes[subCommand.type],
768
+ name: subCommand.name,
769
+ options: optionFormat,
770
+ };
771
+ };
772
+ const parseSubGroupCommand = async (subGroupName, subName) => {
773
+ const subGroup = this.options.find(
774
+ o => (o.name == subGroupName || o.nameLocalized == subGroupName) && o.type == 'SUB_COMMAND_GROUP',
775
+ );
776
+ if (!subGroup) {
777
+ throw buildError(
778
+ 'SubGroupCommand',
779
+ subGroupName,
780
+ this.options.map((o, i) => ` #${i + 1} Name: ${o.name}`).join('\n'),
781
+ 'is not a valid sub group command',
782
+ );
783
+ }
784
+ const data = await parseSubCommand(subName, options, subGroup);
785
+ return {
786
+ type: ApplicationCommandOptionTypes[subGroup.type],
787
+ name: subGroup.name,
788
+ options: [data],
789
+ };
790
+ };
791
+ async function addDataFromAttachment(data, client) {
792
+ const data_ = await MessagePayload.resolveFile(data);
793
+ if (!data_.file) {
794
+ throw new TypeError(
795
+ 'The attachment data must be a BufferResolvable or Stream or FileOptions of MessageAttachment',
796
+ );
797
+ }
798
+ if (client.options.usingNewAttachmentAPI === true) {
799
+ const attachments_ = await getAttachments(client, message.channelId, data_);
800
+ await uploadFile(data_.file, attachments_[0].upload_url);
801
+ const id = attachments.length;
802
+ attachments.push({
803
+ id: id,
804
+ filename: data_.name,
805
+ uploaded_filename: attachments_[0].upload_filename,
806
+ });
807
+ return id;
808
+ } else {
809
+ const id = attachments.length;
810
+ attachments.push({
811
+ id: id,
812
+ filename: data_.name,
813
+ });
814
+ attachmentsBuffer.push(data_);
815
+ return id;
816
+ }
817
+ }
818
+ const getDataPost = (dataAdd = [], nonce, autocomplete = false) => {
819
+ if (!Array.isArray(dataAdd) && typeof dataAdd == 'object') {
820
+ dataAdd = [dataAdd];
821
+ }
822
+ const data = {
823
+ type: autocomplete ? InteractionTypes.APPLICATION_COMMAND_AUTOCOMPLETE : InteractionTypes.APPLICATION_COMMAND,
824
+ application_id: this.applicationId,
825
+ guild_id: message.guildId,
826
+ channel_id: message.channelId,
827
+ session_id: this.client.session_id,
828
+ data: {
829
+ version: this.version,
830
+ id: this.id,
831
+ name: this.name,
832
+ type: ApplicationCommandTypes[this.type],
833
+ options: dataAdd,
834
+ attachments: attachments,
835
+ },
836
+ nonce,
837
+ };
838
+ if (this.guildId) {
839
+ data.data.guild_id = message.guildId;
840
+ }
841
+ return data;
842
+ };
843
+ const getAutoResponse = async (sendData, value) => {
844
+ let nonce = SnowflakeUtil.generate();
845
+ const data = getDataPost(sendData, nonce, true);
846
+ await this.client.api.interactions.post({
847
+ data,
848
+ files: attachmentsBuffer,
849
+ });
850
+ return new Promise(resolve => {
851
+ const handler = data => {
852
+ timeout.refresh();
853
+ if (data.nonce !== nonce) return;
854
+ clearTimeout(timeout);
855
+ this.client.removeListener(Events.APPLICATION_COMMAND_AUTOCOMPLETE_RESPONSE, handler);
856
+ this.client.decrementMaxListeners();
857
+ if (data.choices.length > 1) {
858
+ // Find best match name
859
+ const bestMatch = findBestMatch(
860
+ value,
861
+ data.choices.map(c => c.name),
862
+ );
863
+ const result = data.choices.find(c => c.name == bestMatch.bestMatch.target);
864
+ resolve(result.value);
865
+ } else {
866
+ resolve(value);
867
+ }
868
+ };
869
+ const timeout = setTimeout(() => {
870
+ this.client.removeListener(Events.APPLICATION_COMMAND_AUTOCOMPLETE_RESPONSE, handler);
871
+ this.client.decrementMaxListeners();
872
+ resolve(value);
873
+ }, this.client.options.interactionTimeout).unref();
874
+ this.client.incrementMaxListeners();
875
+ this.client.on(Events.APPLICATION_COMMAND_AUTOCOMPLETE_RESPONSE, handler);
876
+ });
877
+ };
878
+ const sendData = async (optionsData = []) => {
879
+ let nonce = SnowflakeUtil.generate();
880
+ const data = getDataPost(optionsData, nonce);
881
+ await this.client.api.interactions.post({
882
+ data,
883
+ useFormDataPayloadJSON: true,
884
+ files: attachmentsBuffer,
885
+ });
886
+ this.client._interactionCache.set(nonce, {
887
+ channelId: message.channelId,
888
+ guildId: message.guildId,
889
+ metadata: data,
890
+ });
891
+ return new Promise((resolve, reject) => {
892
+ const handler = data => {
893
+ timeout.refresh();
894
+ if (data.metadata?.nonce !== nonce) return;
895
+ clearTimeout(timeout);
896
+ this.client.removeListener('interactionResponse', handler);
897
+ this.client.decrementMaxListeners();
898
+ if (data.status) {
899
+ resolve(data.metadata);
900
+ } else {
901
+ reject(
902
+ new Error('INTERACTION_ERROR', {
903
+ cause: data,
904
+ }),
905
+ );
906
+ }
907
+ };
908
+ const timeout = setTimeout(() => {
909
+ this.client.removeListener('interactionResponse', handler);
910
+ this.client.decrementMaxListeners();
911
+ reject(
912
+ new Error('INTERACTION_TIMEOUT', {
913
+ cause: data,
914
+ }),
915
+ );
916
+ }, this.client.options.interactionTimeout).unref();
917
+ this.client.incrementMaxListeners();
918
+ this.client.on('interactionResponse', handler);
919
+ });
920
+ };
921
+ // SubCommandArray length max 2
922
+ // length = 0 => no sub command
923
+ // length = 1 => sub command
924
+ // length = 2 => sub command group + sub command
925
+ switch (subCommandArray.length) {
926
+ case 0: {
927
+ const valueRequired = this.options?.filter(o => o.required).length || 0;
928
+ for (let i = 0; i < options.length; i++) {
929
+ const optionInput = this.options[i];
930
+ const value = options[i];
931
+ await parseOption(optionInput, value);
932
+ }
933
+ if (valueRequired > options.length) {
934
+ throw new Error(`Value required missing\nDebug:
935
+ Required: ${valueRequired} - Options: ${optionFormat.length}`);
936
+ }
937
+ return sendData(optionFormat);
938
+ }
939
+ case 1: {
940
+ const optionsData = await parseSubCommand(subCommandArray[0], options);
941
+ return sendData(optionsData);
942
+ }
943
+ case 2: {
944
+ const optionsData = await parseSubGroupCommand(subCommandArray[0], subCommandArray[1], options);
945
+ return sendData(optionsData);
946
+ }
947
+ }
948
+ }
949
+ /**
950
+ * Message Context Menu
951
+ * @param {Message} message Discord Message
952
+ * @returns {Promise<InteractionResponse>}
953
+ */
954
+ async sendContextMenu(message) {
955
+ if (!(message instanceof Message())) {
956
+ throw new TypeError('The message must be a Discord.Message');
957
+ }
958
+ if (this.type == 'CHAT_INPUT') return false;
959
+ const nonce = SnowflakeUtil.generate();
960
+ const data = {
961
+ type: InteractionTypes.APPLICATION_COMMAND,
962
+ application_id: this.applicationId,
963
+ guild_id: message.guildId,
964
+ channel_id: message.channelId,
965
+ session_id: this.client.session_id,
966
+ data: {
967
+ version: this.version,
968
+ id: this.id,
969
+ name: this.name,
970
+ type: ApplicationCommandTypes[this.type],
971
+ target_id: ApplicationCommandTypes[this.type] == 1 ? message.author.id : message.id,
972
+ },
973
+ nonce,
974
+ };
975
+ if (this.guildId) {
976
+ data.data.guild_id = message.guildId;
977
+ }
978
+ await this.client.api.interactions.post({
979
+ data,
980
+ useFormDataPayloadJSON: true,
981
+ });
982
+ this.client._interactionCache.set(nonce, {
983
+ channelId: message.channelId,
984
+ guildId: message.guildId,
985
+ metadata: data,
986
+ });
987
+ return new Promise((resolve, reject) => {
988
+ const handler = data => {
989
+ timeout.refresh();
990
+ if (data.metadata?.nonce !== nonce) return;
991
+ clearTimeout(timeout);
992
+ this.client.removeListener('interactionResponse', handler);
993
+ this.client.decrementMaxListeners();
994
+ if (data.status) {
995
+ resolve(data.metadata);
996
+ } else {
997
+ reject(
998
+ new Error('INTERACTION_ERROR', {
999
+ cause: data,
1000
+ }),
1001
+ );
1002
+ }
1003
+ };
1004
+ const timeout = setTimeout(() => {
1005
+ this.client.removeListener('interactionResponse', handler);
1006
+ this.client.decrementMaxListeners();
1007
+ reject(
1008
+ new Error('INTERACTION_TIMEOUT', {
1009
+ cause: data,
1010
+ }),
1011
+ );
1012
+ }, this.client.options.interactionTimeout).unref();
1013
+ this.client.incrementMaxListeners();
1014
+ this.client.on('interactionResponse', handler);
1015
+ });
1016
+ }
580
1017
  }
581
1018
 
582
1019
  module.exports = ApplicationCommand;
@@ -2,9 +2,6 @@
2
2
 
3
3
  const { ApplicationRoleConnectionMetadataTypes } = require('../util/Constants');
4
4
 
5
- /**
6
- * Role connection metadata object for an application.
7
- */
8
5
  class ApplicationRoleConnectionMetadata {
9
6
  constructor(data) {
10
7
  /**
@@ -194,7 +194,7 @@ class AutoModerationRule extends Base {
194
194
  * @returns {Promise<AutoModerationRule>}
195
195
  */
196
196
  setKeywordFilter(keywordFilter, reason) {
197
- return this.edit({ triggerMetadata: { ...this.triggerMetadata, keywordFilter }, reason });
197
+ return this.edit({ triggerMetadata: { keywordFilter }, reason });
198
198
  }
199
199
 
200
200
  /**
@@ -205,7 +205,7 @@ class AutoModerationRule extends Base {
205
205
  * @returns {Promise<AutoModerationRule>}
206
206
  */
207
207
  setRegexPatterns(regexPatterns, reason) {
208
- return this.edit({ triggerMetadata: { ...this.triggerMetadata, regexPatterns }, reason });
208
+ return this.edit({ triggerMetadata: { regexPatterns }, reason });
209
209
  }
210
210
 
211
211
  /**
@@ -215,7 +215,7 @@ class AutoModerationRule extends Base {
215
215
  * @returns {Promise<AutoModerationRule>}
216
216
  */
217
217
  setPresets(presets, reason) {
218
- return this.edit({ triggerMetadata: { ...this.triggerMetadata, presets }, reason });
218
+ return this.edit({ triggerMetadata: { presets }, reason });
219
219
  }
220
220
 
221
221
  /**
@@ -225,7 +225,7 @@ class AutoModerationRule extends Base {
225
225
  * @returns {Promise<AutoModerationRule>}
226
226
  */
227
227
  setAllowList(allowList, reason) {
228
- return this.edit({ triggerMetadata: { ...this.triggerMetadata, allowList }, reason });
228
+ return this.edit({ triggerMetadata: { allowList }, reason });
229
229
  }
230
230
 
231
231
  /**
@@ -235,7 +235,7 @@ class AutoModerationRule extends Base {
235
235
  * @returns {Promise<AutoModerationRule>}
236
236
  */
237
237
  setMentionTotalLimit(mentionTotalLimit, reason) {
238
- return this.edit({ triggerMetadata: { ...this.triggerMetadata, mentionTotalLimit }, reason });
238
+ return this.edit({ triggerMetadata: { mentionTotalLimit }, reason });
239
239
  }
240
240
 
241
241
  /**
@@ -2,7 +2,6 @@
2
2
 
3
3
  const CommandInteractionOptionResolver = require('./CommandInteractionOptionResolver');
4
4
  const Interaction = require('./Interaction');
5
- const { Error } = require('../errors');
6
5
  const { InteractionResponseTypes, ApplicationCommandOptionTypes } = require('../util/Constants');
7
6
 
8
7
  /**
@@ -3,6 +3,7 @@
3
3
  const GuildChannel = require('./GuildChannel');
4
4
  const TextBasedChannel = require('./interfaces/TextBasedChannel');
5
5
  const GuildTextThreadManager = require('../managers/GuildTextThreadManager');
6
+ const InteractionManager = require('../managers/InteractionManager');
6
7
  const MessageManager = require('../managers/MessageManager');
7
8
 
8
9
  /**
@@ -20,6 +21,12 @@ class BaseGuildTextChannel extends GuildChannel {
20
21
  */
21
22
  this.messages = new MessageManager(this);
22
23
 
24
+ /**
25
+ * A manager of the interactions sent to this channel
26
+ * @type {InteractionManager}
27
+ */
28
+ this.interactions = new InteractionManager(this);
29
+
23
30
  /**
24
31
  * A manager of the threads belonging to this channel
25
32
  * @type {GuildTextThreadManager}
@@ -74,16 +81,6 @@ class BaseGuildTextChannel extends GuildChannel {
74
81
  this.defaultAutoArchiveDuration = data.default_auto_archive_duration;
75
82
  }
76
83
 
77
- if ('default_thread_rate_limit_per_user' in data) {
78
- /**
79
- * The initial rate limit per user (slowmode) to set on newly created threads in a channel.
80
- * @type {?number}
81
- */
82
- this.defaultThreadRateLimitPerUser = data.default_thread_rate_limit_per_user;
83
- } else {
84
- this.defaultThreadRateLimitPerUser ??= null;
85
- }
86
-
87
84
  if ('messages' in data) {
88
85
  for (const message of data.messages) this.messages._add(message);
89
86
  }
@@ -180,10 +177,15 @@ class BaseGuildTextChannel extends GuildChannel {
180
177
  sendTyping() {}
181
178
  createMessageCollector() {}
182
179
  awaitMessages() {}
180
+ createMessageComponentCollector() {}
181
+ awaitMessageComponent() {}
182
+ bulkDelete() {}
183
183
  fetchWebhooks() {}
184
184
  createWebhook() {}
185
185
  setRateLimitPerUser() {}
186
186
  setNSFW() {}
187
+ sendSlash() {}
188
+ searchInteraction() {}
187
189
  }
188
190
 
189
191
  TextBasedChannel.applyToClass(BaseGuildTextChannel, true);