@velliajs/discord 1.0.2 → 1.0.4

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 (258) hide show
  1. package/README.md +4 -11
  2. package/package.json +3 -3
  3. package/src/client/BaseClient.js +7 -28
  4. package/src/client/Client.js +116 -283
  5. package/src/client/WebhookClient.js +17 -59
  6. package/src/client/actions/Action.js +0 -10
  7. package/src/client/actions/ActionsManager.js +3 -3
  8. package/src/client/actions/ApplicationCommandPermissionsUpdate.js +2 -15
  9. package/src/client/actions/AutoModerationActionExecution.js +1 -6
  10. package/src/client/actions/AutoModerationRuleCreate.js +1 -6
  11. package/src/client/actions/AutoModerationRuleDelete.js +1 -6
  12. package/src/client/actions/AutoModerationRuleUpdate.js +1 -7
  13. package/src/client/actions/ChannelCreate.js +1 -5
  14. package/src/client/actions/ChannelDelete.js +1 -5
  15. package/src/client/actions/GuildAuditLogEntryCreate.js +1 -6
  16. package/src/client/actions/GuildBanAdd.js +1 -5
  17. package/src/client/actions/GuildBanRemove.js +1 -5
  18. package/src/client/actions/GuildDelete.js +6 -14
  19. package/src/client/actions/GuildEmojiCreate.js +1 -5
  20. package/src/client/actions/GuildEmojiDelete.js +1 -5
  21. package/src/client/actions/GuildEmojiUpdate.js +1 -6
  22. package/src/client/actions/GuildEmojisUpdate.js +4 -4
  23. package/src/client/actions/GuildIntegrationsUpdate.js +1 -5
  24. package/src/client/actions/GuildMemberRemove.js +1 -5
  25. package/src/client/actions/GuildMemberUpdate.js +2 -11
  26. package/src/client/actions/GuildRoleCreate.js +1 -5
  27. package/src/client/actions/GuildRoleDelete.js +1 -5
  28. package/src/client/actions/GuildRoleUpdate.js +1 -6
  29. package/src/client/actions/GuildScheduledEventCreate.js +1 -5
  30. package/src/client/actions/GuildScheduledEventDelete.js +1 -5
  31. package/src/client/actions/GuildScheduledEventUpdate.js +1 -6
  32. package/src/client/actions/GuildScheduledEventUserAdd.js +1 -6
  33. package/src/client/actions/GuildScheduledEventUserRemove.js +1 -6
  34. package/src/client/actions/GuildStickerCreate.js +1 -5
  35. package/src/client/actions/GuildStickerDelete.js +1 -5
  36. package/src/client/actions/GuildStickerUpdate.js +1 -6
  37. package/src/client/actions/GuildStickersUpdate.js +4 -4
  38. package/src/client/actions/GuildUpdate.js +1 -6
  39. package/src/client/actions/InteractionCreate.js +3 -7
  40. package/src/client/actions/InviteCreate.js +1 -7
  41. package/src/client/actions/InviteDelete.js +1 -7
  42. package/src/client/actions/MessageCreate.js +1 -5
  43. package/src/client/actions/MessageDelete.js +1 -5
  44. package/src/client/actions/MessageDeleteBulk.js +1 -6
  45. package/src/client/actions/MessageReactionAdd.js +5 -18
  46. package/src/client/actions/MessageReactionRemove.js +5 -16
  47. package/src/client/actions/MessageReactionRemoveAll.js +4 -9
  48. package/src/client/actions/MessageReactionRemoveEmoji.js +1 -5
  49. package/src/client/actions/PresenceUpdate.js +1 -6
  50. package/src/client/actions/StageInstanceCreate.js +1 -5
  51. package/src/client/actions/StageInstanceDelete.js +1 -5
  52. package/src/client/actions/StageInstanceUpdate.js +1 -6
  53. package/src/client/actions/ThreadCreate.js +1 -6
  54. package/src/client/actions/ThreadDelete.js +1 -5
  55. package/src/client/actions/ThreadListSync.js +2 -7
  56. package/src/client/actions/ThreadMemberUpdate.js +2 -7
  57. package/src/client/actions/ThreadMembersUpdate.js +2 -9
  58. package/src/client/actions/TypingStart.js +1 -5
  59. package/src/client/actions/UserUpdate.js +1 -8
  60. package/src/client/actions/VoiceStateUpdate.js +4 -9
  61. package/src/client/actions/WebhooksUpdate.js +1 -6
  62. package/src/client/voice/ClientVoiceManager.js +3 -13
  63. package/src/client/websocket/WebSocketManager.js +25 -117
  64. package/src/client/websocket/WebSocketShard.js +29 -116
  65. package/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.js +2 -8
  66. package/src/client/websocket/handlers/CHANNEL_UPDATE.js +1 -6
  67. package/src/client/websocket/handlers/GUILD_CREATE.js +3 -7
  68. package/src/client/websocket/handlers/GUILD_MEMBERS_CHUNK.js +2 -16
  69. package/src/client/websocket/handlers/GUILD_MEMBER_ADD.js +1 -5
  70. package/src/client/websocket/handlers/MESSAGE_UPDATE.js +1 -6
  71. package/src/client/websocket/handlers/RESUMED.js +1 -6
  72. package/src/client/websocket/handlers/THREAD_UPDATE.js +1 -6
  73. package/src/errors/DJSError.js +3 -14
  74. package/src/errors/ErrorCodes.js +2 -164
  75. package/src/index.js +6 -6
  76. package/src/managers/ApplicationCommandManager.js +14 -130
  77. package/src/managers/ApplicationCommandPermissionsManager.js +31 -202
  78. package/src/managers/AutoModerationRuleManager.js +17 -145
  79. package/src/managers/BaseGuildEmojiManager.js +7 -38
  80. package/src/managers/BaseManager.js +2 -10
  81. package/src/managers/CachedManager.js +3 -17
  82. package/src/managers/CategoryChannelChildManager.js +6 -48
  83. package/src/managers/ChannelManager.js +11 -52
  84. package/src/managers/DataManager.js +5 -27
  85. package/src/managers/GuildApplicationCommandManager.js +3 -12
  86. package/src/managers/GuildBanManager.js +16 -105
  87. package/src/managers/GuildChannelManager.js +31 -226
  88. package/src/managers/GuildEmojiManager.js +9 -65
  89. package/src/managers/GuildEmojiRoleManager.js +8 -47
  90. package/src/managers/GuildForumThreadManager.js +5 -39
  91. package/src/managers/GuildInviteManager.js +18 -117
  92. package/src/managers/GuildManager.js +14 -115
  93. package/src/managers/GuildMemberManager.js +38 -256
  94. package/src/managers/GuildMemberRoleManager.js +13 -76
  95. package/src/managers/GuildScheduledEventManager.js +25 -128
  96. package/src/managers/GuildStickerManager.js +16 -96
  97. package/src/managers/GuildTextThreadManager.js +4 -47
  98. package/src/managers/MessageManager.js +23 -137
  99. package/src/managers/PermissionOverwriteManager.js +10 -78
  100. package/src/managers/PresenceManager.js +6 -27
  101. package/src/managers/ReactionManager.js +7 -40
  102. package/src/managers/ReactionUserManager.js +6 -29
  103. package/src/managers/RoleManager.js +29 -177
  104. package/src/managers/StageInstanceManager.js +14 -77
  105. package/src/managers/ThreadManager.js +23 -113
  106. package/src/managers/ThreadMemberManager.js +20 -89
  107. package/src/managers/UserManager.js +13 -65
  108. package/src/managers/VoiceStateManager.js +3 -13
  109. package/src/sharding/Shard.js +42 -158
  110. package/src/sharding/ShardClientUtil.js +17 -101
  111. package/src/sharding/ShardingManager.js +34 -151
  112. package/src/structures/ActionRow.js +4 -21
  113. package/src/structures/ActionRowBuilder.js +3 -13
  114. package/src/structures/AnonymousGuild.js +10 -43
  115. package/src/structures/ApplicationCommand.js +54 -308
  116. package/src/structures/ApplicationRoleConnectionMetadata.js +7 -27
  117. package/src/structures/Attachment.js +16 -65
  118. package/src/structures/AttachmentBuilder.js +13 -58
  119. package/src/structures/AutoModerationActionExecution.js +16 -69
  120. package/src/structures/AutoModerationRule.js +32 -164
  121. package/src/structures/AutocompleteInteraction.js +10 -52
  122. package/src/structures/Base.js +2 -10
  123. package/src/structures/BaseChannel.js +16 -80
  124. package/src/structures/BaseGuild.js +13 -59
  125. package/src/structures/BaseGuildEmoji.js +5 -21
  126. package/src/structures/BaseGuildTextChannel.js +19 -100
  127. package/src/structures/BaseGuildVoiceChannel.js +21 -110
  128. package/src/structures/BaseInteraction.js +40 -196
  129. package/src/structures/BaseSelectMenuComponent.js +6 -29
  130. package/src/structures/ButtonBuilder.js +4 -18
  131. package/src/structures/ButtonComponent.js +7 -34
  132. package/src/structures/ButtonInteraction.js +1 -4
  133. package/src/structures/CategoryChannel.js +5 -30
  134. package/src/structures/ChannelSelectMenuBuilder.js +3 -13
  135. package/src/structures/ChannelSelectMenuComponent.js +2 -9
  136. package/src/structures/ChannelSelectMenuInteraction.js +3 -12
  137. package/src/structures/ChatInputCommandInteraction.js +3 -13
  138. package/src/structures/ClientApplication.js +20 -83
  139. package/src/structures/ClientPresence.js +5 -20
  140. package/src/structures/ClientUser.js +21 -118
  141. package/src/structures/CommandInteraction.js +21 -96
  142. package/src/structures/CommandInteractionOptionResolver.js +26 -147
  143. package/src/structures/Component.js +5 -21
  144. package/src/structures/ContextMenuCommandInteraction.js +4 -18
  145. package/src/structures/DMChannel.js +17 -52
  146. package/src/structures/DirectoryChannel.js +4 -16
  147. package/src/structures/Embed.js +21 -107
  148. package/src/structures/EmbedBuilder.js +4 -18
  149. package/src/structures/Emoji.js +12 -60
  150. package/src/structures/ForumChannel.js +30 -140
  151. package/src/structures/Guild.js +117 -697
  152. package/src/structures/GuildAuditLogs.js +7 -32
  153. package/src/structures/GuildAuditLogsEntry.js +27 -135
  154. package/src/structures/GuildBan.js +6 -26
  155. package/src/structures/GuildChannel.js +36 -188
  156. package/src/structures/GuildEmoji.js +13 -67
  157. package/src/structures/GuildMember.js +47 -270
  158. package/src/structures/GuildPreview.js +19 -84
  159. package/src/structures/GuildPreviewEmoji.js +3 -13
  160. package/src/structures/GuildScheduledEvent.js +46 -250
  161. package/src/structures/GuildTemplate.js +24 -108
  162. package/src/structures/Integration.js +25 -103
  163. package/src/structures/IntegrationApplication.js +8 -32
  164. package/src/structures/InteractionCollector.js +22 -113
  165. package/src/structures/InteractionResponse.js +11 -46
  166. package/src/structures/InteractionWebhook.js +8 -33
  167. package/src/structures/Invite.js +27 -131
  168. package/src/structures/InviteGuild.js +2 -8
  169. package/src/structures/InviteStageInstance.js +9 -39
  170. package/src/structures/MentionableSelectMenuBuilder.js +3 -14
  171. package/src/structures/MentionableSelectMenuComponent.js +1 -4
  172. package/src/structures/MentionableSelectMenuInteraction.js +5 -20
  173. package/src/structures/Message.js +85 -460
  174. package/src/structures/MessageCollector.js +14 -70
  175. package/src/structures/MessageComponentInteraction.js +14 -57
  176. package/src/structures/MessageContextMenuCommandInteraction.js +2 -9
  177. package/src/structures/MessageMentions.js +25 -136
  178. package/src/structures/MessagePayload.js +24 -94
  179. package/src/structures/MessageReaction.js +13 -51
  180. package/src/structures/ModalBuilder.js +3 -13
  181. package/src/structures/ModalSubmitFields.js +5 -22
  182. package/src/structures/ModalSubmitInteraction.js +17 -61
  183. package/src/structures/NewsChannel.js +2 -16
  184. package/src/structures/OAuth2Guild.js +3 -12
  185. package/src/structures/PartialGroupDMChannel.js +7 -27
  186. package/src/structures/PermissionOverwrites.js +20 -99
  187. package/src/structures/Presence.js +45 -190
  188. package/src/structures/ReactionCollector.js +20 -108
  189. package/src/structures/ReactionEmoji.js +2 -10
  190. package/src/structures/Role.js +39 -261
  191. package/src/structures/RoleSelectMenuBuilder.js +3 -13
  192. package/src/structures/RoleSelectMenuComponent.js +1 -4
  193. package/src/structures/RoleSelectMenuInteraction.js +3 -12
  194. package/src/structures/SelectMenuBuilder.js +1 -4
  195. package/src/structures/SelectMenuComponent.js +1 -4
  196. package/src/structures/SelectMenuInteraction.js +1 -4
  197. package/src/structures/SelectMenuOptionBuilder.js +1 -4
  198. package/src/structures/StageChannel.js +12 -84
  199. package/src/structures/StageInstance.js +16 -87
  200. package/src/structures/Sticker.js +25 -124
  201. package/src/structures/StickerPack.js +12 -52
  202. package/src/structures/StringSelectMenuBuilder.js +6 -29
  203. package/src/structures/StringSelectMenuComponent.js +2 -9
  204. package/src/structures/StringSelectMenuInteraction.js +2 -8
  205. package/src/structures/StringSelectMenuOptionBuilder.js +4 -18
  206. package/src/structures/Team.js +11 -52
  207. package/src/structures/TeamMember.js +7 -33
  208. package/src/structures/TextChannel.js +3 -14
  209. package/src/structures/TextInputBuilder.js +3 -13
  210. package/src/structures/TextInputComponent.js +3 -14
  211. package/src/structures/ThreadChannel.js +59 -305
  212. package/src/structures/ThreadMember.js +12 -55
  213. package/src/structures/Typing.js +8 -35
  214. package/src/structures/User.js +29 -151
  215. package/src/structures/UserContextMenuCommandInteraction.js +3 -14
  216. package/src/structures/UserSelectMenuBuilder.js +3 -13
  217. package/src/structures/UserSelectMenuComponent.js +1 -4
  218. package/src/structures/UserSelectMenuInteraction.js +4 -16
  219. package/src/structures/VoiceChannel.js +8 -67
  220. package/src/structures/VoiceRegion.js +6 -23
  221. package/src/structures/VoiceState.js +28 -140
  222. package/src/structures/Webhook.js +37 -227
  223. package/src/structures/WelcomeChannel.js +7 -29
  224. package/src/structures/WelcomeScreen.js +5 -20
  225. package/src/structures/Widget.js +9 -40
  226. package/src/structures/WidgetMember.js +15 -61
  227. package/src/structures/interfaces/Application.js +10 -49
  228. package/src/structures/interfaces/Collector.js +34 -155
  229. package/src/structures/interfaces/InteractionResponses.js +25 -164
  230. package/src/structures/interfaces/TextBasedChannel.js +37 -232
  231. package/src/util/APITypes.js +183 -456
  232. package/src/util/ActivityFlagsBitField.js +3 -15
  233. package/src/util/ApplicationFlagsBitField.js +3 -15
  234. package/src/util/BitField.js +17 -82
  235. package/src/util/ChannelFlagsBitField.js +7 -30
  236. package/src/util/Channels.js +5 -35
  237. package/src/util/Colors.js +3 -38
  238. package/src/util/Components.js +21 -75
  239. package/src/util/Constants.js +17 -144
  240. package/src/util/DataResolver.js +20 -77
  241. package/src/util/Events.js +3 -81
  242. package/src/util/Formatters.js +58 -305
  243. package/src/util/GuildMemberFlagsBitField.js +7 -30
  244. package/src/util/IntentsBitField.js +4 -23
  245. package/src/util/LimitedCollection.js +4 -21
  246. package/src/util/MessageFlagsBitField.js +5 -21
  247. package/src/util/Options.js +24 -137
  248. package/src/util/Partials.js +3 -30
  249. package/src/util/PermissionsBitField.js +12 -67
  250. package/src/util/ShardEvents.js +3 -15
  251. package/src/util/Status.js +3 -17
  252. package/src/util/Sweepers.js +35 -184
  253. package/src/util/SystemChannelFlagsBitField.js +7 -32
  254. package/src/util/ThreadMemberFlagsBitField.js +5 -21
  255. package/src/util/Transformers.js +2 -11
  256. package/src/util/UserFlagsBitField.js +5 -21
  257. package/src/util/Util.js +30 -169
  258. package/src/util/WebSocketShardEvents.js +3 -14
@@ -6,97 +6,47 @@ const BaseInteraction = require('./BaseInteraction');
6
6
  const InteractionWebhook = require('./InteractionWebhook');
7
7
  const InteractionResponses = require('./interfaces/InteractionResponses');
8
8
 
9
- /**
10
- * Represents a command interaction.
11
- * @extends {BaseInteraction}
12
- * @implements {InteractionResponses}
13
- * @abstract
14
- */
9
+
15
10
  class CommandInteraction extends BaseInteraction {
16
11
  constructor(client, data) {
17
12
  super(client, data);
18
13
 
19
- /**
20
- * The id of the channel this interaction was sent in
21
- * @type {Snowflake}
22
- * @name CommandInteraction#channelId
23
- */
14
+
24
15
 
25
- /**
26
- * The invoked application command's id
27
- * @type {Snowflake}
28
- */
16
+
29
17
  this.commandId = data.data.id;
30
18
 
31
- /**
32
- * The invoked application command's name
33
- * @type {string}
34
- */
19
+
35
20
  this.commandName = data.data.name;
36
21
 
37
- /**
38
- * The invoked application command's type
39
- * @type {ApplicationCommandType}
40
- */
22
+
41
23
  this.commandType = data.data.type;
42
24
 
43
- /**
44
- * The id of the guild the invoked application command is registered to
45
- * @type {?Snowflake}
46
- */
25
+
47
26
  this.commandGuildId = data.data.guild_id ?? null;
48
27
 
49
- /**
50
- * Whether the reply to this interaction has been deferred
51
- * @type {boolean}
52
- */
28
+
53
29
  this.deferred = false;
54
30
 
55
- /**
56
- * Whether this interaction has already been replied to
57
- * @type {boolean}
58
- */
31
+
59
32
  this.replied = false;
60
33
 
61
- /**
62
- * Whether the reply to this interaction is ephemeral
63
- * @type {?boolean}
64
- */
34
+
65
35
  this.ephemeral = null;
66
36
 
67
- /**
68
- * An associated interaction webhook, can be used to further interact with this interaction
69
- * @type {InteractionWebhook}
70
- */
37
+
71
38
  this.webhook = new InteractionWebhook(this.client, this.applicationId, this.token);
72
39
  }
73
40
 
74
- /**
75
- * The invoked application command, if it was fetched before
76
- * @type {?ApplicationCommand}
77
- */
41
+
78
42
  get command() {
79
43
  const id = this.commandId;
80
44
  return this.guild?.commands.cache.get(id) ?? this.client.application.commands.cache.get(id) ?? null;
81
45
  }
82
46
 
83
- /**
84
- * Represents the resolved data of a received command interaction.
85
- * @typedef {Object} CommandInteractionResolvedData
86
- * @property {Collection<Snowflake, User>} [users] The resolved users
87
- * @property {Collection<Snowflake, GuildMember|APIGuildMember>} [members] The resolved guild members
88
- * @property {Collection<Snowflake, Role|APIRole>} [roles] The resolved roles
89
- * @property {Collection<Snowflake, BaseChannel|APIChannel>} [channels] The resolved channels
90
- * @property {Collection<Snowflake, Message|APIMessage>} [messages] The resolved messages
91
- * @property {Collection<Snowflake, Attachment>} [attachments] The resolved attachments
92
- */
93
-
94
- /**
95
- * Transforms the resolved received from the API.
96
- * @param {APIInteractionDataResolved} resolved The received resolved objects
97
- * @returns {CommandInteractionResolvedData}
98
- * @private
99
- */
47
+
48
+
49
+
100
50
  transformResolved({ members, users, channels, roles, messages, attachments }) {
101
51
  const result = {};
102
52
 
@@ -147,31 +97,9 @@ class CommandInteraction extends BaseInteraction {
147
97
  return result;
148
98
  }
149
99
 
150
- /**
151
- * Represents an option of a received command interaction.
152
- * @typedef {Object} CommandInteractionOption
153
- * @property {string} name The name of the option
154
- * @property {ApplicationCommandOptionType} type The type of the option
155
- * @property {boolean} [autocomplete] Whether the autocomplete interaction is enabled for a
156
- * {@link ApplicationCommandOptionType.String}, {@link ApplicationCommandOptionType.Integer} or
157
- * {@link ApplicationCommandOptionType.Number} option
158
- * @property {string|number|boolean} [value] The value of the option
159
- * @property {CommandInteractionOption[]} [options] Additional options if this option is a
160
- * subcommand (group)
161
- * @property {User} [user] The resolved user
162
- * @property {GuildMember|APIGuildMember} [member] The resolved member
163
- * @property {GuildChannel|ThreadChannel|APIChannel} [channel] The resolved channel
164
- * @property {Role|APIRole} [role] The resolved role
165
- * @property {Attachment} [attachment] The resolved attachment
166
- */
167
-
168
- /**
169
- * Transforms an option received from the API.
170
- * @param {APIApplicationCommandOption} option The received option
171
- * @param {APIInteractionDataResolved} resolved The resolved interaction data
172
- * @returns {CommandInteractionOption}
173
- * @private
174
- */
100
+
101
+
102
+
175
103
  transformOption(option, resolved) {
176
104
  const result = {
177
105
  name: option.name,
@@ -201,8 +129,8 @@ class CommandInteraction extends BaseInteraction {
201
129
  return result;
202
130
  }
203
131
 
204
- // These are here only for documentation purposes - they are implemented by InteractionResponses
205
- /* eslint-disable no-empty-function */
132
+
133
+
206
134
  deferReply() {}
207
135
  reply() {}
208
136
  fetchReply() {}
@@ -217,8 +145,5 @@ InteractionResponses.applyToClass(CommandInteraction, ['deferUpdate', 'update'])
217
145
 
218
146
  module.exports = CommandInteraction;
219
147
 
220
- /* eslint-disable max-len */
221
- /**
222
- * @external APIInteractionDataResolved
223
- * @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-resolved-data-structure}
224
- */
148
+
149
+
@@ -3,74 +3,40 @@
3
3
  const { ApplicationCommandOptionType } = require('discord-api-types/v10');
4
4
  const { DiscordjsTypeError, ErrorCodes } = require('../errors');
5
5
 
6
- /**
7
- * A resolver for command interaction options.
8
- */
6
+
9
7
  class CommandInteractionOptionResolver {
10
8
  constructor(client, options, resolved) {
11
- /**
12
- * The client that instantiated this.
13
- * @name CommandInteractionOptionResolver#client
14
- * @type {Client}
15
- * @readonly
16
- */
9
+
17
10
  Object.defineProperty(this, 'client', { value: client });
18
11
 
19
- /**
20
- * The name of the subcommand group.
21
- * @type {?string}
22
- * @private
23
- */
12
+
24
13
  this._group = null;
25
14
 
26
- /**
27
- * The name of the subcommand.
28
- * @type {?string}
29
- * @private
30
- */
15
+
31
16
  this._subcommand = null;
32
17
 
33
- /**
34
- * The bottom-level options for the interaction.
35
- * If there is a subcommand (or subcommand and group), this is the options for the subcommand.
36
- * @type {CommandInteractionOption[]}
37
- * @private
38
- */
18
+
39
19
  this._hoistedOptions = options;
40
20
 
41
- // Hoist subcommand group if present
21
+
42
22
  if (this._hoistedOptions[0]?.type === ApplicationCommandOptionType.SubcommandGroup) {
43
23
  this._group = this._hoistedOptions[0].name;
44
24
  this._hoistedOptions = this._hoistedOptions[0].options ?? [];
45
25
  }
46
- // Hoist subcommand if present
26
+
47
27
  if (this._hoistedOptions[0]?.type === ApplicationCommandOptionType.Subcommand) {
48
28
  this._subcommand = this._hoistedOptions[0].name;
49
29
  this._hoistedOptions = this._hoistedOptions[0].options ?? [];
50
30
  }
51
31
 
52
- /**
53
- * The interaction options array.
54
- * @name CommandInteractionOptionResolver#data
55
- * @type {ReadonlyArray<CommandInteractionOption>}
56
- * @readonly
57
- */
32
+
58
33
  Object.defineProperty(this, 'data', { value: Object.freeze([...options]) });
59
34
 
60
- /**
61
- * The interaction resolved data
62
- * @name CommandInteractionOptionResolver#resolved
63
- * @type {?Readonly<CommandInteractionResolvedData>}
64
- */
35
+
65
36
  Object.defineProperty(this, 'resolved', { value: resolved ? Object.freeze(resolved) : null });
66
37
  }
67
38
 
68
- /**
69
- * Gets an option by its name.
70
- * @param {string} name The name of the option.
71
- * @param {boolean} [required=false] Whether to throw an error if the option is not found.
72
- * @returns {?CommandInteractionOption} The option, if found.
73
- */
39
+
74
40
  get(name, required = false) {
75
41
  const option = this._hoistedOptions.find(opt => opt.name === name);
76
42
  if (!option) {
@@ -82,15 +48,7 @@ class CommandInteractionOptionResolver {
82
48
  return option;
83
49
  }
84
50
 
85
- /**
86
- * Gets an option by name and property and checks its type.
87
- * @param {string} name The name of the option.
88
- * @param {ApplicationCommandOptionType[]} allowedTypes The allowed types of the option.
89
- * @param {string[]} properties The properties to check for for `required`.
90
- * @param {boolean} required Whether to throw an error if the option is not found.
91
- * @returns {?CommandInteractionOption} The option, if found.
92
- * @private
93
- */
51
+
94
52
  _getTypedOption(name, allowedTypes, properties, required) {
95
53
  const option = this.get(name, required);
96
54
  if (!option) {
@@ -103,11 +61,7 @@ class CommandInteractionOptionResolver {
103
61
  return option;
104
62
  }
105
63
 
106
- /**
107
- * Gets the selected subcommand.
108
- * @param {boolean} [required=true] Whether to throw an error if there is no subcommand.
109
- * @returns {?string} The name of the selected subcommand, or null if not set and not required.
110
- */
64
+
111
65
  getSubcommand(required = true) {
112
66
  if (required && !this._subcommand) {
113
67
  throw new DiscordjsTypeError(ErrorCodes.CommandInteractionOptionNoSubcommand);
@@ -115,11 +69,7 @@ class CommandInteractionOptionResolver {
115
69
  return this._subcommand;
116
70
  }
117
71
 
118
- /**
119
- * Gets the selected subcommand group.
120
- * @param {boolean} [required=false] Whether to throw an error if there is no subcommand group.
121
- * @returns {?string} The name of the selected subcommand group, or null if not set and not required.
122
- */
72
+
123
73
  getSubcommandGroup(required = false) {
124
74
  if (required && !this._group) {
125
75
  throw new DiscordjsTypeError(ErrorCodes.CommandInteractionOptionNoSubcommandGroup);
@@ -127,25 +77,13 @@ class CommandInteractionOptionResolver {
127
77
  return this._group;
128
78
  }
129
79
 
130
- /**
131
- * Gets a boolean option.
132
- * @param {string} name The name of the option.
133
- * @param {boolean} [required=false] Whether to throw an error if the option is not found.
134
- * @returns {?boolean} The value of the option, or null if not set and not required.
135
- */
80
+
136
81
  getBoolean(name, required = false) {
137
82
  const option = this._getTypedOption(name, [ApplicationCommandOptionType.Boolean], ['value'], required);
138
83
  return option?.value ?? null;
139
84
  }
140
85
 
141
- /**
142
- * Gets a channel option.
143
- * @param {string} name The name of the option.
144
- * @param {boolean} [required=false] Whether to throw an error if the option is not found.
145
- * @param {ChannelType[]} [channelTypes=[]] The allowed types of channels. If empty, all channel types are allowed.
146
- * @returns {?(GuildChannel|ThreadChannel|APIChannel)}
147
- * The value of the option, or null if not set and not required.
148
- */
86
+
149
87
  getChannel(name, required = false, channelTypes = []) {
150
88
  const option = this._getTypedOption(name, [ApplicationCommandOptionType.Channel], ['channel'], required);
151
89
  const channel = option?.channel ?? null;
@@ -162,45 +100,25 @@ class CommandInteractionOptionResolver {
162
100
  return channel;
163
101
  }
164
102
 
165
- /**
166
- * Gets a string option.
167
- * @param {string} name The name of the option.
168
- * @param {boolean} [required=false] Whether to throw an error if the option is not found.
169
- * @returns {?string} The value of the option, or null if not set and not required.
170
- */
103
+
171
104
  getString(name, required = false) {
172
105
  const option = this._getTypedOption(name, [ApplicationCommandOptionType.String], ['value'], required);
173
106
  return option?.value ?? null;
174
107
  }
175
108
 
176
- /**
177
- * Gets an integer option.
178
- * @param {string} name The name of the option.
179
- * @param {boolean} [required=false] Whether to throw an error if the option is not found.
180
- * @returns {?number} The value of the option, or null if not set and not required.
181
- */
109
+
182
110
  getInteger(name, required = false) {
183
111
  const option = this._getTypedOption(name, [ApplicationCommandOptionType.Integer], ['value'], required);
184
112
  return option?.value ?? null;
185
113
  }
186
114
 
187
- /**
188
- * Gets a number option.
189
- * @param {string} name The name of the option.
190
- * @param {boolean} [required=false] Whether to throw an error if the option is not found.
191
- * @returns {?number} The value of the option, or null if not set and not required.
192
- */
115
+
193
116
  getNumber(name, required = false) {
194
117
  const option = this._getTypedOption(name, [ApplicationCommandOptionType.Number], ['value'], required);
195
118
  return option?.value ?? null;
196
119
  }
197
120
 
198
- /**
199
- * Gets a user option.
200
- * @param {string} name The name of the option.
201
- * @param {boolean} [required=false] Whether to throw an error if the option is not found.
202
- * @returns {?User} The value of the option, or null if not set and not required.
203
- */
121
+
204
122
  getUser(name, required = false) {
205
123
  const option = this._getTypedOption(
206
124
  name,
@@ -211,12 +129,7 @@ class CommandInteractionOptionResolver {
211
129
  return option?.user ?? null;
212
130
  }
213
131
 
214
- /**
215
- * Gets a member option.
216
- * @param {string} name The name of the option.
217
- * @returns {?(GuildMember|APIGuildMember)}
218
- * The value of the option, or null if the user is not present in the guild or the option is not set.
219
- */
132
+
220
133
  getMember(name) {
221
134
  const option = this._getTypedOption(
222
135
  name,
@@ -227,12 +140,7 @@ class CommandInteractionOptionResolver {
227
140
  return option?.member ?? null;
228
141
  }
229
142
 
230
- /**
231
- * Gets a role option.
232
- * @param {string} name The name of the option.
233
- * @param {boolean} [required=false] Whether to throw an error if the option is not found.
234
- * @returns {?(Role|APIRole)} The value of the option, or null if not set and not required.
235
- */
143
+
236
144
  getRole(name, required = false) {
237
145
  const option = this._getTypedOption(
238
146
  name,
@@ -243,24 +151,13 @@ class CommandInteractionOptionResolver {
243
151
  return option?.role ?? null;
244
152
  }
245
153
 
246
- /**
247
- * Gets an attachment option.
248
- * @param {string} name The name of the option.
249
- * @param {boolean} [required=false] Whether to throw an error if the option is not found.
250
- * @returns {?Attachment} The value of the option, or null if not set and not required.
251
- */
154
+
252
155
  getAttachment(name, required = false) {
253
156
  const option = this._getTypedOption(name, [ApplicationCommandOptionType.Attachment], ['attachment'], required);
254
157
  return option?.attachment ?? null;
255
158
  }
256
159
 
257
- /**
258
- * Gets a mentionable option.
259
- * @param {string} name The name of the option.
260
- * @param {boolean} [required=false] Whether to throw an error if the option is not found.
261
- * @returns {?(User|GuildMember|APIGuildMember|Role|APIRole)}
262
- * The value of the option, or null if not set and not required.
263
- */
160
+
264
161
  getMentionable(name, required = false) {
265
162
  const option = this._getTypedOption(
266
163
  name,
@@ -271,33 +168,15 @@ class CommandInteractionOptionResolver {
271
168
  return option?.member ?? option?.user ?? option?.role ?? null;
272
169
  }
273
170
 
274
- /**
275
- * Gets a message option.
276
- * @param {string} name The name of the option.
277
- * @param {boolean} [required=false] Whether to throw an error if the option is not found.
278
- * @returns {?Message}
279
- * The value of the option, or null if not set and not required.
280
- */
171
+
281
172
  getMessage(name, required = false) {
282
173
  const option = this._getTypedOption(name, ['_MESSAGE'], ['message'], required);
283
174
  return option?.message ?? null;
284
175
  }
285
176
 
286
- /**
287
- * The full autocomplete option object.
288
- * @typedef {Object} AutocompleteFocusedOption
289
- * @property {string} name The name of the option
290
- * @property {ApplicationCommandOptionType} type The type of the application command option
291
- * @property {string} value The value of the option
292
- * @property {boolean} focused Whether this option is currently in focus for autocomplete
293
- */
177
+
294
178
 
295
- /**
296
- * Gets the focused option.
297
- * @param {boolean} [getFull=false] Whether to get the full option object
298
- * @returns {string|AutocompleteFocusedOption}
299
- * The value of the option, or the whole option if getFull is true
300
- */
179
+
301
180
  getFocused(getFull = false) {
302
181
  const focusedOption = this._hoistedOptions.find(option => option.focused);
303
182
  if (!focusedOption) throw new DiscordjsTypeError(ErrorCodes.AutocompleteInteractionOptionNoFocusedOption);
@@ -2,32 +2,19 @@
2
2
 
3
3
  const isEqual = require('fast-deep-equal');
4
4
 
5
- /**
6
- * Represents a component
7
- */
5
+
8
6
  class Component {
9
7
  constructor(data) {
10
- /**
11
- * The API data associated with this component
12
- * @type {APIMessageComponent}
13
- */
8
+
14
9
  this.data = data;
15
10
  }
16
11
 
17
- /**
18
- * The type of the component
19
- * @type {ComponentType}
20
- * @readonly
21
- */
12
+
22
13
  get type() {
23
14
  return this.data.type;
24
15
  }
25
16
 
26
- /**
27
- * Whether or not the given components are equal
28
- * @param {Component|APIMessageComponent} other The component to compare against
29
- * @returns {boolean}
30
- */
17
+
31
18
  equals(other) {
32
19
  if (other instanceof Component) {
33
20
  return isEqual(other.data, this.data);
@@ -35,10 +22,7 @@ class Component {
35
22
  return isEqual(other, this.data);
36
23
  }
37
24
 
38
- /**
39
- * Returns the API-compatible JSON for this component
40
- * @returns {APIMessageComponent}
41
- */
25
+
42
26
  toJSON() {
43
27
  return { ...this.data };
44
28
  }
@@ -7,36 +7,22 @@ const CommandInteractionOptionResolver = require('./CommandInteractionOptionReso
7
7
 
8
8
  const getMessage = lazy(() => require('./Message').Message);
9
9
 
10
- /**
11
- * Represents a context menu interaction.
12
- * @extends {CommandInteraction}
13
- */
10
+
14
11
  class ContextMenuCommandInteraction extends CommandInteraction {
15
12
  constructor(client, data) {
16
13
  super(client, data);
17
- /**
18
- * The target of the interaction, parsed into options
19
- * @type {CommandInteractionOptionResolver}
20
- */
14
+
21
15
  this.options = new CommandInteractionOptionResolver(
22
16
  this.client,
23
17
  this.resolveContextMenuOptions(data.data),
24
18
  this.transformResolved(data.data.resolved),
25
19
  );
26
20
 
27
- /**
28
- * The id of the target of this interaction
29
- * @type {Snowflake}
30
- */
21
+
31
22
  this.targetId = data.data.target_id;
32
23
  }
33
24
 
34
- /**
35
- * Resolves and transforms options received from the API for a context menu interaction.
36
- * @param {APIApplicationCommandInteractionData} data The interaction data
37
- * @returns {CommandInteractionOption[]}
38
- * @private
39
- */
25
+
40
26
  resolveContextMenuOptions({ target_id, resolved }) {
41
27
  const result = [];
42
28
 
@@ -7,22 +7,15 @@ const TextBasedChannel = require('./interfaces/TextBasedChannel');
7
7
  const MessageManager = require('../managers/MessageManager');
8
8
  const Partials = require('../util/Partials');
9
9
 
10
- /**
11
- * Represents a direct message channel between two users.
12
- * @extends {BaseChannel}
13
- * @implements {TextBasedChannel}
14
- */
10
+
15
11
  class DMChannel extends BaseChannel {
16
12
  constructor(client, data) {
17
13
  super(client, data);
18
14
 
19
- // Override the channel type so partials have a known type
15
+
20
16
  this.type = ChannelType.DM;
21
17
 
22
- /**
23
- * A manager of the messages belonging to this channel
24
- * @type {MessageManager}
25
- */
18
+
26
19
  this.messages = new MessageManager(this);
27
20
  }
28
21
 
@@ -32,10 +25,7 @@ class DMChannel extends BaseChannel {
32
25
  if (data.recipients) {
33
26
  const recipient = data.recipients[0];
34
27
 
35
- /**
36
- * The recipient's id
37
- * @type {Snowflake}
38
- */
28
+
39
29
  this.recipientId = recipient.id;
40
30
 
41
31
  if ('username' in recipient || this.client.options.partials.includes(Partials.Users)) {
@@ -44,65 +34,40 @@ class DMChannel extends BaseChannel {
44
34
  }
45
35
 
46
36
  if ('last_message_id' in data) {
47
- /**
48
- * The channel's last message id, if one was sent
49
- * @type {?Snowflake}
50
- */
37
+
51
38
  this.lastMessageId = data.last_message_id;
52
39
  }
53
40
 
54
41
  if ('last_pin_timestamp' in data) {
55
- /**
56
- * The timestamp when the last pinned message was pinned, if there was one
57
- * @type {?number}
58
- */
42
+
59
43
  this.lastPinTimestamp = Date.parse(data.last_pin_timestamp);
60
44
  } else {
61
45
  this.lastPinTimestamp ??= null;
62
46
  }
63
47
  }
64
48
 
65
- /**
66
- * Whether this DMChannel is a partial
67
- * @type {boolean}
68
- * @readonly
69
- */
49
+
70
50
  get partial() {
71
51
  return this.lastMessageId === undefined;
72
52
  }
73
53
 
74
- /**
75
- * The recipient on the other end of the DM
76
- * @type {?User}
77
- * @readonly
78
- */
54
+
79
55
  get recipient() {
80
56
  return this.client.users.resolve(this.recipientId);
81
57
  }
82
58
 
83
- /**
84
- * Fetch this DMChannel.
85
- * @param {boolean} [force=true] Whether to skip the cache check and request the API
86
- * @returns {Promise<DMChannel>}
87
- */
59
+
88
60
  fetch(force = true) {
89
61
  return this.client.users.createDM(this.recipientId, { force });
90
62
  }
91
63
 
92
- /**
93
- * When concatenated with a string, this automatically returns the recipient's mention instead of the
94
- * DMChannel object.
95
- * @returns {string}
96
- * @example
97
- * // Logs: Hello from <@123456789012345678>!
98
- * console.log(`Hello from ${channel}!`);
99
- */
64
+
100
65
  toString() {
101
66
  return userMention(this.recipientId);
102
67
  }
103
68
 
104
- // These are here only for documentation purposes - they are implemented by TextBasedChannel
105
- /* eslint-disable no-empty-function */
69
+
70
+
106
71
  get lastMessage() {}
107
72
  get lastPinAt() {}
108
73
  send() {}
@@ -111,11 +76,11 @@ class DMChannel extends BaseChannel {
111
76
  awaitMessages() {}
112
77
  createMessageComponentCollector() {}
113
78
  awaitMessageComponent() {}
114
- // Doesn't work on DM channels; bulkDelete() {}
115
- // Doesn't work on DM channels; fetchWebhooks() {}
116
- // Doesn't work on DM channels; createWebhook() {}
117
- // Doesn't work on DM channels; setRateLimitPerUser() {}
118
- // Doesn't work on DM channels; setNSFW() {}
79
+
80
+
81
+
82
+
83
+
119
84
  }
120
85
 
121
86
  TextBasedChannel.applyToClass(DMChannel, true, [