@ovencord/discord.js 14.16.3

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 (332) hide show
  1. package/LICENSE +191 -0
  2. package/README.md +148 -0
  3. package/package.json +73 -0
  4. package/src/client/Client.ts +967 -0
  5. package/src/client/actions/Action.ts +141 -0
  6. package/src/client/actions/ActionsManager.ts +138 -0
  7. package/src/client/actions/ChannelCreate.ts +21 -0
  8. package/src/client/actions/ChannelDelete.ts +20 -0
  9. package/src/client/actions/ChannelUpdate.ts +38 -0
  10. package/src/client/actions/GuildChannelsPositionUpdate.ts +17 -0
  11. package/src/client/actions/GuildEmojiCreate.ts +17 -0
  12. package/src/client/actions/GuildEmojiDelete.ts +16 -0
  13. package/src/client/actions/GuildEmojiUpdate.ts +17 -0
  14. package/src/client/actions/GuildEmojisUpdate.ts +30 -0
  15. package/src/client/actions/GuildMemberRemove.ts +29 -0
  16. package/src/client/actions/GuildMemberUpdate.ts +41 -0
  17. package/src/client/actions/GuildRoleCreate.ts +23 -0
  18. package/src/client/actions/GuildRoleDelete.ts +26 -0
  19. package/src/client/actions/GuildRolesPositionUpdate.ts +17 -0
  20. package/src/client/actions/GuildScheduledEventDelete.ts +28 -0
  21. package/src/client/actions/GuildScheduledEventUserAdd.ts +29 -0
  22. package/src/client/actions/GuildScheduledEventUserRemove.ts +29 -0
  23. package/src/client/actions/GuildSoundboardSoundDelete.ts +26 -0
  24. package/src/client/actions/GuildStickerCreate.ts +17 -0
  25. package/src/client/actions/GuildStickerDelete.ts +16 -0
  26. package/src/client/actions/GuildStickerUpdate.ts +17 -0
  27. package/src/client/actions/GuildStickersUpdate.ts +30 -0
  28. package/src/client/actions/GuildUpdate.ts +30 -0
  29. package/src/client/actions/InteractionCreate.ts +104 -0
  30. package/src/client/actions/MessageCreate.ts +38 -0
  31. package/src/client/actions/MessageDelete.ts +29 -0
  32. package/src/client/actions/MessageDeleteBulk.ts +45 -0
  33. package/src/client/actions/MessagePollVoteAdd.ts +37 -0
  34. package/src/client/actions/MessagePollVoteRemove.ts +35 -0
  35. package/src/client/actions/MessageReactionAdd.ts +68 -0
  36. package/src/client/actions/MessageReactionRemove.ts +47 -0
  37. package/src/client/actions/MessageReactionRemoveAll.ts +30 -0
  38. package/src/client/actions/MessageReactionRemoveEmoji.ts +25 -0
  39. package/src/client/actions/MessageUpdate.ts +22 -0
  40. package/src/client/actions/StageInstanceCreate.ts +25 -0
  41. package/src/client/actions/StageInstanceDelete.ts +28 -0
  42. package/src/client/actions/StageInstanceUpdate.ts +27 -0
  43. package/src/client/actions/ThreadCreate.ts +22 -0
  44. package/src/client/actions/ThreadMembersUpdate.ts +45 -0
  45. package/src/client/actions/TypingStart.ts +26 -0
  46. package/src/client/actions/UserUpdate.ts +33 -0
  47. package/src/client/voice/ClientVoiceManager.ts +46 -0
  48. package/src/client/websocket/handlers/APPLICATION_COMMAND_PERMISSIONS_UPDATE.ts +19 -0
  49. package/src/client/websocket/handlers/AUTO_MODERATION_ACTION_EXECUTION.ts +17 -0
  50. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_CREATE.ts +18 -0
  51. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_DELETE.ts +21 -0
  52. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_UPDATE.ts +20 -0
  53. package/src/client/websocket/handlers/CHANNEL_CREATE.ts +4 -0
  54. package/src/client/websocket/handlers/CHANNEL_DELETE.ts +4 -0
  55. package/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.ts +22 -0
  56. package/src/client/websocket/handlers/CHANNEL_UPDATE.ts +16 -0
  57. package/src/client/websocket/handlers/ENTITLEMENT_CREATE.ts +14 -0
  58. package/src/client/websocket/handlers/ENTITLEMENT_DELETE.ts +18 -0
  59. package/src/client/websocket/handlers/ENTITLEMENT_UPDATE.ts +16 -0
  60. package/src/client/websocket/handlers/GUILD_AUDIT_LOG_ENTRY_CREATE.ts +19 -0
  61. package/src/client/websocket/handlers/GUILD_BAN_ADD.ts +15 -0
  62. package/src/client/websocket/handlers/GUILD_BAN_REMOVE.ts +20 -0
  63. package/src/client/websocket/handlers/GUILD_CREATE.ts +34 -0
  64. package/src/client/websocket/handlers/GUILD_DELETE.ts +36 -0
  65. package/src/client/websocket/handlers/GUILD_EMOJIS_UPDATE.ts +4 -0
  66. package/src/client/websocket/handlers/GUILD_INTEGRATIONS_UPDATE.ts +15 -0
  67. package/src/client/websocket/handlers/GUILD_MEMBERS_CHUNK.ts +40 -0
  68. package/src/client/websocket/handlers/GUILD_MEMBER_ADD.ts +17 -0
  69. package/src/client/websocket/handlers/GUILD_MEMBER_REMOVE.ts +4 -0
  70. package/src/client/websocket/handlers/GUILD_MEMBER_UPDATE.ts +4 -0
  71. package/src/client/websocket/handlers/GUILD_ROLE_CREATE.ts +4 -0
  72. package/src/client/websocket/handlers/GUILD_ROLE_DELETE.ts +4 -0
  73. package/src/client/websocket/handlers/GUILD_ROLE_UPDATE.ts +21 -0
  74. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_CREATE.ts +17 -0
  75. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_DELETE.ts +4 -0
  76. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_UPDATE.ts +19 -0
  77. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_ADD.ts +4 -0
  78. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_REMOVE.ts +4 -0
  79. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUNDS_UPDATE.ts +24 -0
  80. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_CREATE.ts +18 -0
  81. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_DELETE.ts +4 -0
  82. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_UPDATE.ts +20 -0
  83. package/src/client/websocket/handlers/GUILD_STICKERS_UPDATE.ts +4 -0
  84. package/src/client/websocket/handlers/GUILD_UPDATE.ts +4 -0
  85. package/src/client/websocket/handlers/INTERACTION_CREATE.ts +4 -0
  86. package/src/client/websocket/handlers/INVITE_CREATE.ts +20 -0
  87. package/src/client/websocket/handlers/INVITE_DELETE.ts +23 -0
  88. package/src/client/websocket/handlers/MESSAGE_CREATE.ts +4 -0
  89. package/src/client/websocket/handlers/MESSAGE_DELETE.ts +4 -0
  90. package/src/client/websocket/handlers/MESSAGE_DELETE_BULK.ts +4 -0
  91. package/src/client/websocket/handlers/MESSAGE_POLL_VOTE_ADD.ts +4 -0
  92. package/src/client/websocket/handlers/MESSAGE_POLL_VOTE_REMOVE.ts +4 -0
  93. package/src/client/websocket/handlers/MESSAGE_REACTION_ADD.ts +4 -0
  94. package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE.ts +4 -0
  95. package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_ALL.ts +4 -0
  96. package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_EMOJI.ts +4 -0
  97. package/src/client/websocket/handlers/MESSAGE_UPDATE.ts +16 -0
  98. package/src/client/websocket/handlers/PRESENCE_UPDATE.ts +42 -0
  99. package/src/client/websocket/handlers/RATE_LIMITED.ts +23 -0
  100. package/src/client/websocket/handlers/READY.ts +29 -0
  101. package/src/client/websocket/handlers/SOUNDBOARD_SOUNDS.ts +24 -0
  102. package/src/client/websocket/handlers/STAGE_INSTANCE_CREATE.ts +4 -0
  103. package/src/client/websocket/handlers/STAGE_INSTANCE_DELETE.ts +4 -0
  104. package/src/client/websocket/handlers/STAGE_INSTANCE_UPDATE.ts +4 -0
  105. package/src/client/websocket/handlers/SUBSCRIPTION_CREATE.ts +14 -0
  106. package/src/client/websocket/handlers/SUBSCRIPTION_DELETE.ts +16 -0
  107. package/src/client/websocket/handlers/SUBSCRIPTION_UPDATE.ts +16 -0
  108. package/src/client/websocket/handlers/THREAD_CREATE.ts +4 -0
  109. package/src/client/websocket/handlers/THREAD_DELETE.ts +17 -0
  110. package/src/client/websocket/handlers/THREAD_LIST_SYNC.ts +50 -0
  111. package/src/client/websocket/handlers/THREAD_MEMBERS_UPDATE.ts +4 -0
  112. package/src/client/websocket/handlers/THREAD_MEMBER_UPDATE.ts +25 -0
  113. package/src/client/websocket/handlers/THREAD_UPDATE.ts +16 -0
  114. package/src/client/websocket/handlers/TYPING_START.ts +4 -0
  115. package/src/client/websocket/handlers/USER_UPDATE.ts +4 -0
  116. package/src/client/websocket/handlers/VOICE_CHANNEL_EFFECT_SEND.ts +16 -0
  117. package/src/client/websocket/handlers/VOICE_SERVER_UPDATE.ts +5 -0
  118. package/src/client/websocket/handlers/VOICE_STATE_UPDATE.ts +37 -0
  119. package/src/client/websocket/handlers/WEBHOOKS_UPDATE.ts +16 -0
  120. package/src/client/websocket/handlers/index.ts +74 -0
  121. package/src/errors/DJSError.ts +50 -0
  122. package/src/errors/ErrorCodes.ts +277 -0
  123. package/src/errors/Messages.ts +155 -0
  124. package/src/errors/index.ts +6 -0
  125. package/src/index.ts +241 -0
  126. package/src/managers/ApplicationCommandManager.ts +303 -0
  127. package/src/managers/ApplicationCommandPermissionsManager.ts +453 -0
  128. package/src/managers/ApplicationEmojiManager.ts +149 -0
  129. package/src/managers/AutoModerationRuleManager.ts +307 -0
  130. package/src/managers/BaseManager.ts +13 -0
  131. package/src/managers/CachedManager.ts +56 -0
  132. package/src/managers/CategoryChannelChildManager.ts +81 -0
  133. package/src/managers/ChannelManager.ts +194 -0
  134. package/src/managers/DMMessageManager.ts +15 -0
  135. package/src/managers/DataManager.ts +38 -0
  136. package/src/managers/EntitlementManager.ts +182 -0
  137. package/src/managers/GuildApplicationCommandManager.ts +29 -0
  138. package/src/managers/GuildBanManager.ts +221 -0
  139. package/src/managers/GuildChannelManager.ts +552 -0
  140. package/src/managers/GuildEmojiManager.ts +262 -0
  141. package/src/managers/GuildEmojiRoleManager.ts +134 -0
  142. package/src/managers/GuildForumThreadManager.ts +84 -0
  143. package/src/managers/GuildInviteManager.ts +236 -0
  144. package/src/managers/GuildManager.ts +265 -0
  145. package/src/managers/GuildMemberManager.ts +619 -0
  146. package/src/managers/GuildMemberRoleManager.ts +230 -0
  147. package/src/managers/GuildMessageManager.ts +31 -0
  148. package/src/managers/GuildScheduledEventManager.ts +330 -0
  149. package/src/managers/GuildSoundboardSoundManager.ts +157 -0
  150. package/src/managers/GuildStickerManager.ts +192 -0
  151. package/src/managers/GuildTextThreadManager.ts +91 -0
  152. package/src/managers/MessageManager.ts +352 -0
  153. package/src/managers/PartialGroupDMMessageManager.ts +15 -0
  154. package/src/managers/PermissionOverwriteManager.ts +174 -0
  155. package/src/managers/PollAnswerVoterManager.ts +59 -0
  156. package/src/managers/PresenceManager.ts +60 -0
  157. package/src/managers/ReactionManager.ts +72 -0
  158. package/src/managers/ReactionUserManager.ts +82 -0
  159. package/src/managers/RoleManager.ts +432 -0
  160. package/src/managers/StageInstanceManager.ts +166 -0
  161. package/src/managers/SubscriptionManager.ts +83 -0
  162. package/src/managers/ThreadManager.ts +210 -0
  163. package/src/managers/ThreadMemberManager.ts +194 -0
  164. package/src/managers/UserManager.ts +139 -0
  165. package/src/managers/VoiceStateManager.ts +61 -0
  166. package/src/sharding/Shard.ts +513 -0
  167. package/src/sharding/ShardClientUtil.ts +293 -0
  168. package/src/sharding/ShardingManager.ts +374 -0
  169. package/src/structures/ActionRow.ts +31 -0
  170. package/src/structures/AnnouncementChannel.ts +25 -0
  171. package/src/structures/AnonymousGuild.ts +110 -0
  172. package/src/structures/ApplicationCommand.ts +675 -0
  173. package/src/structures/ApplicationEmoji.ts +189 -0
  174. package/src/structures/ApplicationRoleConnectionMetadata.ts +54 -0
  175. package/src/structures/Attachment.ts +189 -0
  176. package/src/structures/AuthorizingIntegrationOwners.ts +63 -0
  177. package/src/structures/AutoModerationActionExecution.ts +138 -0
  178. package/src/structures/AutoModerationRule.ts +325 -0
  179. package/src/structures/AutocompleteInteraction.ts +115 -0
  180. package/src/structures/Base.ts +37 -0
  181. package/src/structures/BaseChannel.ts +188 -0
  182. package/src/structures/BaseGuild.ts +134 -0
  183. package/src/structures/BaseGuildEmoji.ts +113 -0
  184. package/src/structures/BaseGuildTextChannel.ts +230 -0
  185. package/src/structures/BaseGuildVoiceChannel.ts +270 -0
  186. package/src/structures/BaseInteraction.ts +393 -0
  187. package/src/structures/BaseInvite.ts +192 -0
  188. package/src/structures/BaseSelectMenuComponent.ts +58 -0
  189. package/src/structures/ButtonComponent.ts +68 -0
  190. package/src/structures/ButtonInteraction.ts +8 -0
  191. package/src/structures/CategoryChannel.ts +46 -0
  192. package/src/structures/ChannelSelectMenuComponent.ts +18 -0
  193. package/src/structures/ChannelSelectMenuInteraction.ts +34 -0
  194. package/src/structures/ChatInputCommandInteraction.ts +43 -0
  195. package/src/structures/ClientApplication.ts +470 -0
  196. package/src/structures/ClientPresence.ts +87 -0
  197. package/src/structures/ClientUser.ts +219 -0
  198. package/src/structures/CommandInteraction.ts +193 -0
  199. package/src/structures/CommandInteractionOptionResolver.ts +336 -0
  200. package/src/structures/Component.ts +59 -0
  201. package/src/structures/ContainerComponent.ts +63 -0
  202. package/src/structures/ContextMenuCommandInteraction.ts +68 -0
  203. package/src/structures/DMChannel.ts +148 -0
  204. package/src/structures/DirectoryChannel.ts +40 -0
  205. package/src/structures/Embed.ts +251 -0
  206. package/src/structures/Emoji.ts +61 -0
  207. package/src/structures/Entitlement.ts +206 -0
  208. package/src/structures/FileComponent.ts +41 -0
  209. package/src/structures/ForumChannel.ts +31 -0
  210. package/src/structures/GroupDMInvite.ts +34 -0
  211. package/src/structures/Guild.ts +1605 -0
  212. package/src/structures/GuildAuditLogs.ts +99 -0
  213. package/src/structures/GuildAuditLogsEntry.ts +557 -0
  214. package/src/structures/GuildBan.ts +65 -0
  215. package/src/structures/GuildChannel.ts +515 -0
  216. package/src/structures/GuildEmoji.ts +159 -0
  217. package/src/structures/GuildInvite.ts +233 -0
  218. package/src/structures/GuildMember.ts +643 -0
  219. package/src/structures/GuildOnboarding.ts +73 -0
  220. package/src/structures/GuildOnboardingPrompt.ts +93 -0
  221. package/src/structures/GuildOnboardingPromptOption.ts +100 -0
  222. package/src/structures/GuildPreview.ts +218 -0
  223. package/src/structures/GuildPreviewEmoji.ts +28 -0
  224. package/src/structures/GuildScheduledEvent.ts +593 -0
  225. package/src/structures/GuildTemplate.ts +229 -0
  226. package/src/structures/Integration.ts +257 -0
  227. package/src/structures/IntegrationApplication.ts +84 -0
  228. package/src/structures/InteractionCallback.ts +86 -0
  229. package/src/structures/InteractionCallbackResource.ts +57 -0
  230. package/src/structures/InteractionCallbackResponse.ts +35 -0
  231. package/src/structures/InteractionCollector.ts +260 -0
  232. package/src/structures/InteractionWebhook.ts +65 -0
  233. package/src/structures/InviteGuild.ts +22 -0
  234. package/src/structures/LabelComponent.ts +51 -0
  235. package/src/structures/MediaChannel.ts +8 -0
  236. package/src/structures/MediaGalleryComponent.ts +31 -0
  237. package/src/structures/MediaGalleryItem.ts +54 -0
  238. package/src/structures/MentionableSelectMenuComponent.ts +8 -0
  239. package/src/structures/MentionableSelectMenuInteraction.ts +76 -0
  240. package/src/structures/Message.ts +1202 -0
  241. package/src/structures/MessageCollector.ts +155 -0
  242. package/src/structures/MessageComponentInteraction.ts +132 -0
  243. package/src/structures/MessageContextMenuCommandInteraction.ts +18 -0
  244. package/src/structures/MessageMentions.ts +327 -0
  245. package/src/structures/MessagePayload.ts +325 -0
  246. package/src/structures/MessageReaction.ts +219 -0
  247. package/src/structures/ModalComponentResolver.ts +237 -0
  248. package/src/structures/ModalSubmitInteraction.ts +260 -0
  249. package/src/structures/OAuth2Guild.ts +30 -0
  250. package/src/structures/PartialGroupDMChannel.ts +151 -0
  251. package/src/structures/PermissionOverwrites.ts +222 -0
  252. package/src/structures/Poll.ts +195 -0
  253. package/src/structures/PollAnswer.ts +100 -0
  254. package/src/structures/Presence.ts +448 -0
  255. package/src/structures/PrimaryEntryPointCommandInteraction.ts +8 -0
  256. package/src/structures/ReactionCollector.ts +245 -0
  257. package/src/structures/ReactionEmoji.ts +30 -0
  258. package/src/structures/Role.ts +543 -0
  259. package/src/structures/RoleSelectMenuComponent.ts +8 -0
  260. package/src/structures/RoleSelectMenuInteraction.ts +34 -0
  261. package/src/structures/SKU.ts +62 -0
  262. package/src/structures/SectionComponent.ts +44 -0
  263. package/src/structures/SeparatorComponent.ts +29 -0
  264. package/src/structures/SoundboardSound.ts +176 -0
  265. package/src/structures/StageChannel.ts +118 -0
  266. package/src/structures/StageInstance.ts +173 -0
  267. package/src/structures/Sticker.ts +300 -0
  268. package/src/structures/StickerPack.ts +111 -0
  269. package/src/structures/StringSelectMenuComponent.ts +18 -0
  270. package/src/structures/StringSelectMenuInteraction.ts +21 -0
  271. package/src/structures/Subscription.ts +138 -0
  272. package/src/structures/Team.ts +131 -0
  273. package/src/structures/TeamMember.ts +77 -0
  274. package/src/structures/TextChannel.ts +33 -0
  275. package/src/structures/TextDisplayComponent.ts +18 -0
  276. package/src/structures/TextInputComponent.ts +28 -0
  277. package/src/structures/ThreadChannel.ts +680 -0
  278. package/src/structures/ThreadMember.ts +125 -0
  279. package/src/structures/ThreadOnlyChannel.ts +276 -0
  280. package/src/structures/ThumbnailComponent.ts +51 -0
  281. package/src/structures/Typing.ts +81 -0
  282. package/src/structures/UnfurledMediaItem.ts +33 -0
  283. package/src/structures/User.ts +511 -0
  284. package/src/structures/UserContextMenuCommandInteraction.ts +28 -0
  285. package/src/structures/UserSelectMenuComponent.ts +8 -0
  286. package/src/structures/UserSelectMenuInteraction.ts +54 -0
  287. package/src/structures/VoiceChannel.ts +119 -0
  288. package/src/structures/VoiceChannelEffect.ts +92 -0
  289. package/src/structures/VoiceRegion.ts +52 -0
  290. package/src/structures/VoiceState.ts +346 -0
  291. package/src/structures/Webhook.ts +526 -0
  292. package/src/structures/WelcomeChannel.ts +67 -0
  293. package/src/structures/WelcomeScreen.ts +53 -0
  294. package/src/structures/Widget.ts +110 -0
  295. package/src/structures/WidgetMember.ts +124 -0
  296. package/src/structures/interfaces/Application.ts +179 -0
  297. package/src/structures/interfaces/Collector.ts +372 -0
  298. package/src/structures/interfaces/InteractionResponses.ts +384 -0
  299. package/src/structures/interfaces/TextBasedChannel.ts +430 -0
  300. package/src/util/APITypes.ts +690 -0
  301. package/src/util/ActivityFlagsBitField.ts +26 -0
  302. package/src/util/ApplicationFlagsBitField.ts +43 -0
  303. package/src/util/AttachmentFlagsBitField.ts +26 -0
  304. package/src/util/BitField.ts +178 -0
  305. package/src/util/ChannelFlagsBitField.ts +43 -0
  306. package/src/util/Channels.ts +165 -0
  307. package/src/util/Colors.ts +72 -0
  308. package/src/util/Components.ts +285 -0
  309. package/src/util/Constants.ts +251 -0
  310. package/src/util/DataResolver.ts +146 -0
  311. package/src/util/Enums.ts +10 -0
  312. package/src/util/Events.ts +178 -0
  313. package/src/util/GuildMemberFlagsBitField.ts +43 -0
  314. package/src/util/IntentsBitField.ts +35 -0
  315. package/src/util/InviteFlagsBitField.ts +26 -0
  316. package/src/util/Invites.ts +27 -0
  317. package/src/util/LimitedCollection.ts +73 -0
  318. package/src/util/MessageFlagsBitField.ts +43 -0
  319. package/src/util/Options.ts +215 -0
  320. package/src/util/Partials.ts +50 -0
  321. package/src/util/PermissionsBitField.ts +113 -0
  322. package/src/util/RoleFlagsBitField.ts +26 -0
  323. package/src/util/SKUFlagsBitField.ts +26 -0
  324. package/src/util/ShardEvents.ts +26 -0
  325. package/src/util/Status.ts +16 -0
  326. package/src/util/Sweepers.ts +532 -0
  327. package/src/util/Symbols.ts +1 -0
  328. package/src/util/SystemChannelFlagsBitField.ts +45 -0
  329. package/src/util/ThreadMemberFlagsBitField.ts +33 -0
  330. package/src/util/Transformers.ts +123 -0
  331. package/src/util/UserFlagsBitField.ts +33 -0
  332. package/src/util/Util.ts +519 -0
@@ -0,0 +1,166 @@
1
+ import { Routes } from 'discord-api-types/v10';
2
+ import { DiscordjsTypeError, DiscordjsError, ErrorCodes } from '../errors/index.js';
3
+ import { StageInstance } from '../structures/StageInstance.js';
4
+ import { CachedManager } from './CachedManager.js';
5
+
6
+ /**
7
+ * Manages API methods for {@link StageInstance} objects and holds their cache.
8
+ *
9
+ * @extends {CachedManager}
10
+ */
11
+ export class StageInstanceManager extends CachedManager {
12
+ public guild: any;
13
+ constructor(guild, iterable) {
14
+ super(guild.client, StageInstance, iterable);
15
+
16
+ /**
17
+ * The guild this manager belongs to
18
+ *
19
+ * @type {Guild}
20
+ */
21
+ this.guild = guild;
22
+ }
23
+
24
+ /**
25
+ * The cache of this Manager
26
+ *
27
+ * @type {Collection<Snowflake, StageInstance>}
28
+ * @name StageInstanceManager#cache
29
+ */
30
+
31
+ /**
32
+ * Options used to create a stage instance.
33
+ *
34
+ * @typedef {Object} StageInstanceCreateOptions
35
+ * @property {string} topic The topic of the stage instance
36
+ * @property {StageInstancePrivacyLevel} [privacyLevel] The privacy level of the stage instance
37
+ * @property {boolean} [sendStartNotification] Whether to notify `@everyone` that the stage instance has started
38
+ * @property {GuildScheduledEventResolvable} [guildScheduledEvent]
39
+ * The guild scheduled event associated with the stage instance
40
+ */
41
+
42
+ /**
43
+ * Data that can be resolved to a Stage Channel object. This can be:
44
+ * - A StageChannel
45
+ * - A Snowflake
46
+ *
47
+ * @typedef {StageChannel|Snowflake} StageChannelResolvable
48
+ */
49
+
50
+ /**
51
+ * Creates a new stage instance.
52
+ *
53
+ * @param {StageChannelResolvable} channel The stage channel to associate the created stage instance to
54
+ * @param {StageInstanceCreateOptions} options The options to create the stage instance
55
+ * @returns {Promise<StageInstance>}
56
+ * @example
57
+ * // Create a stage instance
58
+ * guild.stageInstances.create('1234567890123456789', {
59
+ * topic: 'A very creative topic',
60
+ * privacyLevel: GuildPrivacyLevel.GuildOnly
61
+ * })
62
+ * .then(stageInstance => console.log(stageInstance))
63
+ * .catch(console.error);
64
+ */
65
+ async create(channel, options) {
66
+ const channelId = this.guild.channels.resolveId(channel);
67
+ if (!channelId) throw new DiscordjsError(ErrorCodes.StageChannelResolve);
68
+ if (typeof options !== 'object') throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'options', 'object', true);
69
+ const { guildScheduledEvent, topic, privacyLevel, sendStartNotification } = options;
70
+
71
+ const guildScheduledEventId = guildScheduledEvent && this.resolveId(guildScheduledEvent);
72
+
73
+ const data = await this.client.rest.post(Routes.stageInstances(), {
74
+ body: {
75
+ channel_id: channelId,
76
+ topic,
77
+ privacy_level: privacyLevel,
78
+ send_start_notification: sendStartNotification,
79
+ guild_scheduled_event_id: guildScheduledEventId,
80
+ },
81
+ });
82
+
83
+ return this._add(data);
84
+ }
85
+
86
+ /**
87
+ * Fetches the stage instance associated with a stage channel, if it exists.
88
+ *
89
+ * @param {StageChannelResolvable} channel The stage channel whose associated stage instance is to be fetched
90
+ * @param {BaseFetchOptions} [options] Additional options for this fetch
91
+ * @returns {Promise<StageInstance>}
92
+ * @example
93
+ * // Fetch a stage instance
94
+ * guild.stageInstances.fetch('1234567890123456789')
95
+ * .then(stageInstance => console.log(stageInstance))
96
+ * .catch(console.error);
97
+ */
98
+ async fetch(channel, { cache = true, force = false } = {}) {
99
+ const channelId = this.guild.channels.resolveId(channel);
100
+ if (!channelId) throw new DiscordjsError(ErrorCodes.StageChannelResolve);
101
+
102
+ if (!force) {
103
+ const existing = this.cache.find(stageInstance => stageInstance.channelId === channelId);
104
+ if (existing) return existing;
105
+ }
106
+
107
+ const data = await this.client.rest.get(Routes.stageInstance(channelId));
108
+ return this._add(data, cache);
109
+ }
110
+
111
+ /**
112
+ * Options used to edit an existing stage instance.
113
+ *
114
+ * @typedef {Object} StageInstanceEditOptions
115
+ * @property {string} [topic] The new topic of the stage instance
116
+ * @property {StageInstancePrivacyLevel} [privacyLevel] The new privacy level of the stage instance
117
+ */
118
+
119
+ /**
120
+ * Edits an existing stage instance.
121
+ *
122
+ * @param {StageChannelResolvable} channel The stage channel whose associated stage instance is to be edited
123
+ * @param {StageInstanceEditOptions} options The options to edit the stage instance
124
+ * @returns {Promise<StageInstance>}
125
+ * @example
126
+ * // Edit a stage instance
127
+ * guild.stageInstances.edit('1234567890123456789', { topic: 'new topic' })
128
+ * .then(stageInstance => console.log(stageInstance))
129
+ * .catch(console.error);
130
+ */
131
+ async edit(channel, options) {
132
+ if (typeof options !== 'object') throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'options', 'object', true);
133
+ const channelId = this.guild.channels.resolveId(channel);
134
+ if (!channelId) throw new DiscordjsError(ErrorCodes.StageChannelResolve);
135
+
136
+ const { topic, privacyLevel } = options;
137
+
138
+ const data = await this.client.rest.patch(Routes.stageInstance(channelId), {
139
+ body: {
140
+ topic,
141
+ privacy_level: privacyLevel,
142
+ },
143
+ });
144
+
145
+ if (this.cache.has(data.id)) {
146
+ const clone = this.cache.get(data.id)._clone();
147
+ clone._patch(data);
148
+ return clone;
149
+ }
150
+
151
+ return this._add(data);
152
+ }
153
+
154
+ /**
155
+ * Deletes an existing stage instance.
156
+ *
157
+ * @param {StageChannelResolvable} channel The stage channel whose associated stage instance is to be deleted
158
+ * @returns {Promise<void>}
159
+ */
160
+ async delete(channel) {
161
+ const channelId = this.guild.channels.resolveId(channel);
162
+ if (!channelId) throw new DiscordjsError(ErrorCodes.StageChannelResolve);
163
+
164
+ await this.client.rest.delete(Routes.stageInstance(channelId));
165
+ }
166
+ }
@@ -0,0 +1,83 @@
1
+ import { Collection } from '@ovencord/collection';
2
+ import { makeURLSearchParams } from '@ovencord/rest';
3
+ import { Routes } from 'discord-api-types/v10';
4
+ import { DiscordjsTypeError, ErrorCodes } from '../errors/index.js';
5
+ import { Subscription } from '../structures/Subscription.js';
6
+ import { resolveSKUId } from '../util/Util.js';
7
+ import { CachedManager } from './CachedManager.js';
8
+
9
+ /**
10
+ * Manages API methods for subscriptions and stores their cache.
11
+ *
12
+ * @extends {CachedManager}
13
+ */
14
+ export class SubscriptionManager extends CachedManager {
15
+ public client: any;
16
+ constructor(client, iterable) {
17
+ super(client, Subscription, iterable);
18
+ }
19
+
20
+ /**
21
+ * The cache of this manager
22
+ *
23
+ * @type {Collection<Snowflake, Subscription>}
24
+ * @name SubscriptionManager#cache
25
+ */
26
+
27
+ /**
28
+ * Options used to fetch a subscription
29
+ *
30
+ * @typedef {BaseFetchOptions} FetchSubscriptionOptions
31
+ * @property {SKUResolvable} sku The SKU to fetch the subscription for
32
+ * @property {Snowflake} subscriptionId The id of the subscription to fetch
33
+ */
34
+
35
+ /**
36
+ * Options used to fetch subscriptions
37
+ *
38
+ * @typedef {Object} FetchSubscriptionsOptions
39
+ * @property {Snowflake} [after] Consider only subscriptions after this subscription id
40
+ * @property {Snowflake} [before] Consider only subscriptions before this subscription id
41
+ * @property {number} [limit] The maximum number of subscriptions to fetch
42
+ * @property {SKUResolvable} sku The SKU to fetch subscriptions for
43
+ * @property {UserResolvable} user The user to fetch entitlements for
44
+ * <warn>If both `before` and `after` are provided, only `before` is respected</warn>
45
+ */
46
+
47
+ /**
48
+ * Fetches subscriptions for this application
49
+ *
50
+ * @param {FetchSubscriptionOptions|FetchSubscriptionsOptions} [options={}] Options for fetching the subscriptions
51
+ * @returns {Promise<Subscription|Collection<Snowflake, Subscription>>}
52
+ */
53
+ async fetch(options = {}) {
54
+ if (typeof options !== 'object') throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'options', 'object', true);
55
+
56
+ const { after, before, cache, limit, sku, subscriptionId, user } = options;
57
+
58
+ const skuId = resolveSKUId(sku);
59
+
60
+ if (!skuId) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'sku', 'SKUResolvable');
61
+
62
+ if (subscriptionId) {
63
+ const subscription = await this.client.rest.get(Routes.skuSubscription(skuId, subscriptionId));
64
+
65
+ return this._add(subscription, cache);
66
+ }
67
+
68
+ const query = makeURLSearchParams({
69
+ limit,
70
+ user_id: this.client.users.resolveId(user) ?? undefined,
71
+ sku_id: skuId,
72
+ before,
73
+ after,
74
+ });
75
+
76
+ const subscriptions = await this.client.rest.get(Routes.skuSubscriptions(skuId), { query });
77
+
78
+ return subscriptions.reduce(
79
+ (coll, subscription) => coll.set(subscription.id, this._add(subscription, cache)),
80
+ new Collection(),
81
+ );
82
+ }
83
+ }
@@ -0,0 +1,210 @@
1
+ import { Collection } from '@ovencord/collection';
2
+ import { makeURLSearchParams } from '@ovencord/rest';
3
+ import { Routes } from 'discord-api-types/v10';
4
+ import { DiscordjsTypeError, ErrorCodes } from '../errors/index.js';
5
+ import { ThreadChannel } from '../structures/ThreadChannel.js';
6
+ import { MakeCacheOverrideSymbol } from '../util/Symbols.js';
7
+ import { CachedManager } from './CachedManager.js';
8
+
9
+ /**
10
+ * Manages API methods for thread-based channels and stores their cache.
11
+ *
12
+ * @extends {CachedManager}
13
+ */
14
+ export class ThreadManager extends CachedManager {
15
+ public channel: any;
16
+ static [MakeCacheOverrideSymbol] = ThreadManager;
17
+
18
+ constructor(channel, iterable) {
19
+ super(channel.client, ThreadChannel, iterable);
20
+
21
+ /**
22
+ * The channel this Manager belongs to
23
+ *
24
+ * @type {TextChannel|AnnouncementChannel|ForumChannel|MediaChannel}
25
+ */
26
+ this.channel = channel;
27
+ }
28
+
29
+ /**
30
+ * Data that can be resolved to a Thread Channel object. This can be:
31
+ * - A ThreadChannel object
32
+ * - A Snowflake
33
+ *
34
+ * @typedef {ThreadChannel|Snowflake} ThreadChannelResolvable
35
+ */
36
+
37
+ /**
38
+ * The cache of this Manager
39
+ *
40
+ * @type {Collection<Snowflake, ThreadChannel>}
41
+ * @name ThreadManager#cache
42
+ */
43
+
44
+ _add(thread) {
45
+ const existing = this.cache.get(thread.id);
46
+ if (existing) return existing;
47
+ this.cache.set(thread.id, thread);
48
+ return thread;
49
+ }
50
+
51
+ /**
52
+ * Resolves a {@link ThreadChannelResolvable} to a {@link ThreadChannel} object.
53
+ *
54
+ * @method resolve
55
+ * @memberof ThreadManager
56
+ * @instance
57
+ * @param {ThreadChannelResolvable} thread The ThreadChannel resolvable to resolve
58
+ * @returns {?ThreadChannel}
59
+ */
60
+
61
+ /**
62
+ * Resolves a {@link ThreadChannelResolvable} to a {@link ThreadChannel} id.
63
+ *
64
+ * @method resolveId
65
+ * @memberof ThreadManager
66
+ * @instance
67
+ * @param {ThreadChannelResolvable} thread The ThreadChannel resolvable to resolve
68
+ * @returns {?Snowflake}
69
+ */
70
+
71
+ /**
72
+ * Options for fetching multiple threads.
73
+ *
74
+ * @typedef {Object} FetchThreadsOptions
75
+ * @property {FetchArchivedThreadOptions} [archived] Options used to fetch archived threads
76
+ */
77
+
78
+ /**
79
+ * Obtains a thread from Discord, or the channel cache if it's already available.
80
+ *
81
+ * @param {ThreadChannelResolvable|FetchThreadsOptions} [options] The options to fetch threads. If it is a
82
+ * ThreadChannelResolvable then the specified thread will be fetched. Fetches all active threads if `undefined`
83
+ * @param {BaseFetchOptions} [cacheOptions] Additional options for this fetch. <warn>The `force` field gets ignored
84
+ * if `options` is not a {@link ThreadChannelResolvable}</warn>
85
+ * @returns {Promise<?(ThreadChannel|FetchedThreads|FetchedThreadsMore)>}
86
+ * {@link FetchedThreads} if active & {@link FetchedThreadsMore} if archived.
87
+ * @example
88
+ * // Fetch a thread by its id
89
+ * channel.threads.fetch('831955138126104859')
90
+ * .then(channel => console.log(channel.name))
91
+ * .catch(console.error);
92
+ */
93
+ async fetch(options, { cache, force } = {}) {
94
+ if (!options) return this.fetchActive(cache);
95
+ const channel = this.client.channels.resolveId(options);
96
+ if (channel) {
97
+ const threadChannel = await this.client.channels.fetch(channel, { cache, force });
98
+ if (threadChannel.parentId !== this.channel.id) throw new DiscordjsTypeError(ErrorCodes.NotAThreadOfParent);
99
+ return threadChannel;
100
+ }
101
+
102
+ if (options.archived) {
103
+ return this.fetchArchived(options.archived, cache);
104
+ }
105
+
106
+ return this.fetchActive(cache);
107
+ }
108
+
109
+ /**
110
+ * Data that can be resolved to a Date object. This can be:
111
+ * - A Date object
112
+ * - A number representing a timestamp
113
+ * - An {@link https://en.wikipedia.org/wiki/ISO_8601 ISO 8601} string
114
+ *
115
+ * @typedef {Date|number|string} DateResolvable
116
+ */
117
+
118
+ /**
119
+ * The options used to fetch archived threads.
120
+ *
121
+ * @typedef {Object} FetchArchivedThreadOptions
122
+ * @property {string} [type='public'] The type of threads to fetch (`public` or `private`)
123
+ * @property {boolean} [fetchAll=false] Whether to fetch **all** archived threads when `type` is `private`
124
+ * <info>This property requires the {@link PermissionFlagsBits.ManageThreads} permission if `true`.</info>
125
+ * @property {DateResolvable|ThreadChannelResolvable} [before] Only return threads that were archived before this Date
126
+ * or Snowflake
127
+ * <warn>Must be a {@link ThreadChannelResolvable} when `type` is `private` and `fetchAll` is `false`.</warn>
128
+ * @property {number} [limit] Maximum number of threads to return
129
+ */
130
+
131
+ /**
132
+ * Data returned from fetching multiple threads.
133
+ *
134
+ * @typedef {FetchedThreads} FetchedThreadsMore
135
+ * @property {?boolean} hasMore Whether there are potentially additional threads that require a subsequent call
136
+ */
137
+
138
+ /**
139
+ * Obtains a set of archived threads from Discord.
140
+ * <info>This method requires the {@link PermissionFlagsBits.ReadMessageHistory} permission
141
+ * in the parent channel.</info>
142
+ *
143
+ * @param {FetchArchivedThreadOptions} [options] The options to fetch archived threads
144
+ * @param {boolean} [cache=true] Whether to cache the new thread objects if they aren't already
145
+ * @returns {Promise<FetchedThreadsMore>}
146
+ */
147
+ async fetchArchived({ type = 'public', fetchAll = false, before, limit } = {}, cache = true) {
148
+ let path = Routes.channelThreads(this.channel.id, type);
149
+ if (type === 'private' && !fetchAll) {
150
+ path = Routes.channelJoinedArchivedThreads(this.channel.id);
151
+ }
152
+
153
+ let timestamp;
154
+ let id;
155
+ const query = makeURLSearchParams({ limit });
156
+ if (before !== undefined) {
157
+ if (before instanceof ThreadChannel || /^\d{17,19}$/.test(String(before))) {
158
+ id = this.resolveId(before);
159
+ timestamp = this.resolve(before)?.archivedAt?.toISOString();
160
+ const toUse = type === 'private' && !fetchAll ? id : timestamp;
161
+ if (toUse) {
162
+ query.set('before', toUse);
163
+ }
164
+ } else {
165
+ try {
166
+ timestamp = new Date(before).toISOString();
167
+ if (type === 'public' || fetchAll) {
168
+ query.set('before', timestamp);
169
+ }
170
+ } catch {
171
+ throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'before', 'DateResolvable or ThreadChannelResolvable');
172
+ }
173
+ }
174
+ }
175
+
176
+ const raw = await this.client.rest.get(path, { query });
177
+ return this.constructor._mapThreads(raw, this.client, { parent: this.channel, cache });
178
+ }
179
+
180
+ /**
181
+ * Obtains all active threads in the channel.
182
+ *
183
+ * @param {boolean} [cache=true] Whether to cache the fetched data
184
+ * @returns {Promise<FetchedThreads>}
185
+ */
186
+ async fetchActive(cache = true) {
187
+ const data = await this.channel.guild.channels.rawFetchGuildActiveThreads();
188
+ return this.constructor._mapThreads(data, this.client, { parent: this.channel, cache });
189
+ }
190
+
191
+ static _mapThreads(rawThreads, client, { parent, guild, cache }) {
192
+ const threads = rawThreads.threads.reduce((coll, raw) => {
193
+ const thread = client.channels._add(raw, guild ?? parent?.guild, { cache });
194
+ if (parent && thread.parentId !== parent.id) return coll;
195
+ return coll.set(thread.id, thread);
196
+ }, new Collection());
197
+
198
+ // Discord sends the thread id as id in this object
199
+ const threadMembers = rawThreads.members.reduce((coll, raw) => {
200
+ const thread = threads.get(raw.id);
201
+ return thread ? coll.set(raw.user_id, thread.members._add(raw)) : coll;
202
+ }, new Collection());
203
+
204
+ const response = { threads, members: threadMembers };
205
+
206
+ // The GET `/guilds/{guild.id}/threads/active` route does not return `has_more`.
207
+ if ('has_more' in rawThreads) response.hasMore = rawThreads.has_more;
208
+ return response;
209
+ }
210
+ }
@@ -0,0 +1,194 @@
1
+ import { Collection } from '@ovencord/collection';
2
+ import { makeURLSearchParams } from '@ovencord/rest';
3
+ import { Routes } from 'discord-api-types/v10';
4
+ import { DiscordjsTypeError, ErrorCodes } from '../errors/index.js';
5
+ import { ThreadMember } from '../structures/ThreadMember.js';
6
+ import { CachedManager } from './CachedManager.js';
7
+
8
+ /**
9
+ * Manages API methods for GuildMembers and stores their cache.
10
+ *
11
+ * @extends {CachedManager}
12
+ */
13
+ export class ThreadMemberManager extends CachedManager {
14
+ public thread: any;
15
+ constructor(thread, iterable) {
16
+ super(thread.client, ThreadMember, iterable);
17
+
18
+ /**
19
+ * The thread this manager belongs to
20
+ *
21
+ * @type {ThreadChannel}
22
+ */
23
+ this.thread = thread;
24
+ }
25
+
26
+ /**
27
+ * The cache of this Manager
28
+ *
29
+ * @type {Collection<Snowflake, ThreadMember>}
30
+ * @name ThreadMemberManager#cache
31
+ */
32
+
33
+ _add(data, cache = true) {
34
+ const existing = this.cache.get(data.user_id);
35
+ if (cache) existing?._patch(data, { cache });
36
+ if (existing) return existing;
37
+
38
+ const member = new ThreadMember(this.thread, data, { cache });
39
+ if (cache) this.cache.set(data.user_id, member);
40
+ return member;
41
+ }
42
+
43
+ /**
44
+ * Fetches the client user as a ThreadMember of the thread.
45
+ *
46
+ * @param {BaseFetchOptions} [options] The options for fetching the member
47
+ * @returns {Promise<ThreadMember>}
48
+ */
49
+ async fetchMe(options) {
50
+ return this.fetch({ ...options, member: this.client.user.id });
51
+ }
52
+
53
+ /**
54
+ * The client user as a ThreadMember of this ThreadChannel
55
+ *
56
+ * @type {?ThreadMember}
57
+ * @readonly
58
+ */
59
+ get me() {
60
+ return this.cache.get(this.client.user.id) ?? null;
61
+ }
62
+
63
+ /**
64
+ * Data that resolves to give a ThreadMember object. This can be:
65
+ * - A ThreadMember object
66
+ * - A User resolvable
67
+ *
68
+ * @typedef {ThreadMember|UserResolvable} ThreadMemberResolvable
69
+ */
70
+
71
+ /**
72
+ * Resolves a {@link ThreadMemberResolvable} to a {@link ThreadMember} object.
73
+ *
74
+ * @param {ThreadMemberResolvable} member The user that is part of the thread
75
+ * @returns {?GuildMember}
76
+ */
77
+ resolve(member) {
78
+ const memberResolvable = super.resolve(member);
79
+ if (memberResolvable) return memberResolvable;
80
+ const userId = this.client.users.resolveId(member);
81
+ if (userId) return super.cache.get(userId) ?? null;
82
+ return null;
83
+ }
84
+
85
+ /**
86
+ * Resolves a {@link ThreadMemberResolvable} to a {@link ThreadMember} id string.
87
+ *
88
+ * @param {ThreadMemberResolvable} member The user that is part of the guild
89
+ * @returns {?Snowflake}
90
+ */
91
+ resolveId(member) {
92
+ const memberResolvable = super.resolveId(member);
93
+ if (memberResolvable) return memberResolvable;
94
+ const userResolvable = this.client.users.resolveId(member);
95
+ return this.cache.has(userResolvable) ? userResolvable : null;
96
+ }
97
+
98
+ /**
99
+ * Adds a member to the thread.
100
+ *
101
+ * @param {UserResolvable|'@me'} member The member to add
102
+ * @returns {Promise<Snowflake>}
103
+ */
104
+ async add(member) {
105
+ const id = member === '@me' ? member : this.client.users.resolveId(member);
106
+ if (!id) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'member', 'UserResolvable');
107
+ await this.client.rest.put(Routes.threadMembers(this.thread.id, id));
108
+ return id;
109
+ }
110
+
111
+ /**
112
+ * Remove a user from the thread.
113
+ *
114
+ * @param {UserResolvable|'@me'} member The member to remove
115
+ * @returns {Promise<Snowflake>}
116
+ */
117
+ async remove(member) {
118
+ const id = member === '@me' ? member : this.client.users.resolveId(member);
119
+ if (!id) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'member', 'UserResolvable');
120
+ await this.client.rest.delete(Routes.threadMembers(this.thread.id, id));
121
+ return id;
122
+ }
123
+
124
+ /**
125
+ * Options used to fetch a thread member.
126
+ *
127
+ * @typedef {BaseFetchOptions} FetchThreadMemberOptions
128
+ * @property {ThreadMemberResolvable} member The thread member to fetch
129
+ * @property {boolean} [withMember] Whether to also return the guild member associated with this thread member
130
+ */
131
+
132
+ /**
133
+ * Options used to fetch multiple thread members with guild member data.
134
+ * <info>With `withMember` set to `true`, pagination is enabled.</info>
135
+ *
136
+ * @typedef {Object} FetchThreadMembersWithGuildMemberDataOptions
137
+ * @property {true} withMember Whether to also return the guild member data
138
+ * @property {Snowflake} [after] Consider only thread members after this id
139
+ * @property {number} [limit] The maximum number of thread members to return
140
+ * @property {boolean} [cache] Whether to cache the fetched thread members and guild members
141
+ */
142
+
143
+ /**
144
+ * Options used to fetch multiple thread members without guild member data.
145
+ *
146
+ * @typedef {Object} FetchThreadMembersWithoutGuildMemberDataOptions
147
+ * @property {false} [withMember] Whether to also return the guild member data
148
+ * @property {boolean} [cache] Whether to cache the fetched thread members
149
+ */
150
+
151
+ /**
152
+ * Options used to fetch multiple thread members.
153
+ *
154
+ * @typedef {FetchThreadMembersWithGuildMemberDataOptions|
155
+ * FetchThreadMembersWithoutGuildMemberDataOptions} FetchThreadMembersOptions
156
+ */
157
+
158
+ /**
159
+ * Fetches thread member(s) from Discord.
160
+ * <info>This method requires the {@link GatewayIntentBits.GuildMembers} privileged gateway intent.</info>
161
+ *
162
+ * @param {ThreadMemberResolvable|FetchThreadMemberOptions|FetchThreadMembersOptions} [options]
163
+ * Options for fetching thread member(s)
164
+ * @returns {Promise<ThreadMember|Collection<Snowflake, ThreadMember>>}
165
+ */
166
+ async fetch(options) {
167
+ if (!options) return this._fetchMany();
168
+ const { member, withMember, cache, force } = options;
169
+ const resolvedMember = this.resolveId(member ?? options);
170
+ if (resolvedMember) return this._fetchSingle({ member: resolvedMember, withMember, cache, force });
171
+ return this._fetchMany(options);
172
+ }
173
+
174
+ async _fetchSingle({ member, withMember, cache, force = false }) {
175
+ if (!force) {
176
+ const existing = this.cache.get(member);
177
+ if (existing) return existing;
178
+ }
179
+
180
+ const data = await this.client.rest.get(Routes.threadMembers(this.thread.id, member), {
181
+ query: makeURLSearchParams({ with_member: withMember }),
182
+ });
183
+
184
+ return this._add(data, cache);
185
+ }
186
+
187
+ async _fetchMany({ withMember, after, limit, cache } = {}) {
188
+ const data = await this.client.rest.get(Routes.threadMembers(this.thread.id), {
189
+ query: makeURLSearchParams({ with_member: withMember, after, limit }),
190
+ });
191
+
192
+ return data.reduce((col, member) => col.set(member.user_id, this._add(member, cache)), new Collection());
193
+ }
194
+ }