@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,680 @@
1
+ import { lazy } from '@ovencord/util';
2
+ import { ChannelFlags, ChannelType, PermissionFlagsBits, Routes } from 'discord-api-types/v10';
3
+ import { DiscordjsRangeError, ErrorCodes } from '../errors/index.js';
4
+ import { GuildMessageManager } from '../managers/GuildMessageManager.js';
5
+ import { ThreadMemberManager } from '../managers/ThreadMemberManager.js';
6
+ import { ChannelFlagsBitField } from '../util/ChannelFlagsBitField.js';
7
+ import { BaseChannel } from './BaseChannel.js';
8
+ import { TextBasedChannel } from './interfaces/TextBasedChannel.js';
9
+
10
+ const getThreadOnlyChannel = lazy(() => require('./ThreadOnlyChannel.js'));
11
+
12
+ /**
13
+ * Represents a thread channel on Discord.
14
+ *
15
+ * @extends {BaseChannel}
16
+ * @implements {TextBasedChannel}
17
+ */
18
+ export class ThreadChannel extends BaseChannel {
19
+ public client: any;
20
+ public guild: any;
21
+ public guildId: any;
22
+ public ownerId: any;
23
+ public messages: any;
24
+ public members: any;
25
+ public name: any;
26
+ public parentId: any;
27
+ public locked: any;
28
+ public invitable: any;
29
+ public type: any;
30
+ public archived: any;
31
+ public autoArchiveDuration: any;
32
+ public archiveTimestamp: any;
33
+ public _createdTimestamp: any;
34
+ public lastMessageId: any;
35
+ public lastPinTimestamp: any;
36
+ public rateLimitPerUser: any;
37
+ public messageCount: any;
38
+ public memberCount: any;
39
+ public totalMessageSent: any;
40
+ public appliedTags: any;
41
+ constructor(guild, data, client) {
42
+ super(guild?.client ?? client, data, false);
43
+
44
+ /**
45
+ * The guild the thread is in
46
+ *
47
+ * @type {Guild}
48
+ */
49
+ this.guild = guild;
50
+
51
+ /**
52
+ * The id of the guild the channel is in
53
+ *
54
+ * @type {Snowflake}
55
+ */
56
+ this.guildId = guild?.id ?? data.guild_id;
57
+
58
+ /**
59
+ * The id of the member who created this thread
60
+ *
61
+ * @type {Snowflake}
62
+ */
63
+ this.ownerId = data.owner_id;
64
+
65
+ /**
66
+ * A manager of the messages sent to this thread
67
+ *
68
+ * @type {GuildMessageManager}
69
+ */
70
+ this.messages = new GuildMessageManager(this);
71
+
72
+ /**
73
+ * A manager of the members that are part of this thread
74
+ *
75
+ * @type {ThreadMemberManager}
76
+ */
77
+ this.members = new ThreadMemberManager(this);
78
+ this._patch(data);
79
+ }
80
+
81
+ _patch(data) {
82
+ super._patch(data);
83
+
84
+ if ('message' in data) this.messages._add(data.message);
85
+
86
+ if ('name' in data) {
87
+ /**
88
+ * The name of the thread
89
+ *
90
+ * @type {string}
91
+ */
92
+ this.name = data.name;
93
+ }
94
+
95
+ if ('guild_id' in data) {
96
+ this.guildId = data.guild_id;
97
+ }
98
+
99
+ if ('parent_id' in data) {
100
+ /**
101
+ * The id of the parent channel of this thread
102
+ *
103
+ * @type {?Snowflake}
104
+ */
105
+ this.parentId = data.parent_id;
106
+ } else {
107
+ this.parentId ??= null;
108
+ }
109
+
110
+ if ('thread_metadata' in data) {
111
+ /**
112
+ * Whether the thread is locked
113
+ *
114
+ * @type {?boolean}
115
+ */
116
+ this.locked = data.thread_metadata.locked ?? false;
117
+
118
+ /**
119
+ * Whether members without the {@link PermissionFlagsBits.ManageThreads} permission
120
+ * can invite other members to this thread.
121
+ * <info>This property is always `null` in public threads.</info>
122
+ *
123
+ * @type {?boolean}
124
+ */
125
+ this.invitable = this.type === ChannelType.PrivateThread ? (data.thread_metadata.invitable ?? false) : null;
126
+
127
+ /**
128
+ * Whether the thread is archived
129
+ *
130
+ * @type {?boolean}
131
+ */
132
+ this.archived = data.thread_metadata.archived;
133
+
134
+ /**
135
+ * The amount of time (in minutes) after which the thread will automatically archive in case of no recent activity
136
+ *
137
+ * @type {?ThreadAutoArchiveDuration}
138
+ */
139
+ this.autoArchiveDuration = data.thread_metadata.auto_archive_duration;
140
+
141
+ /**
142
+ * The timestamp when the thread's archive status was last changed
143
+ * <info>If the thread was never archived or unarchived, this is the timestamp at which the thread was
144
+ * created</info>
145
+ *
146
+ * @type {?number}
147
+ */
148
+ this.archiveTimestamp = Date.parse(data.thread_metadata.archive_timestamp);
149
+
150
+ if ('create_timestamp' in data.thread_metadata) {
151
+ // Note: this is needed because we can't assign directly to getters
152
+ this._createdTimestamp = Date.parse(data.thread_metadata.create_timestamp);
153
+ }
154
+ } else {
155
+ this.locked ??= null;
156
+ this.archived ??= null;
157
+ this.autoArchiveDuration ??= null;
158
+ this.archiveTimestamp ??= null;
159
+ this.invitable ??= null;
160
+ }
161
+
162
+ this._createdTimestamp ??= this.type === ChannelType.PrivateThread ? super.createdTimestamp : null;
163
+
164
+ if ('last_message_id' in data) {
165
+ /**
166
+ * The last message id sent in this thread, if one was sent
167
+ *
168
+ * @type {?Snowflake}
169
+ */
170
+ this.lastMessageId = data.last_message_id;
171
+ } else {
172
+ this.lastMessageId ??= null;
173
+ }
174
+
175
+ if ('last_pin_timestamp' in data) {
176
+ /**
177
+ * The timestamp when the last pinned message was pinned, if there was one
178
+ *
179
+ * @type {?number}
180
+ */
181
+ this.lastPinTimestamp = data.last_pin_timestamp ? Date.parse(data.last_pin_timestamp) : null;
182
+ } else {
183
+ this.lastPinTimestamp ??= null;
184
+ }
185
+
186
+ if ('rate_limit_per_user' in data) {
187
+ /**
188
+ * The rate limit per user (slowmode) for this thread in seconds
189
+ *
190
+ * @type {?number}
191
+ */
192
+ this.rateLimitPerUser = data.rate_limit_per_user ?? 0;
193
+ } else {
194
+ this.rateLimitPerUser ??= null;
195
+ }
196
+
197
+ if ('message_count' in data) {
198
+ /**
199
+ * The approximate count of messages in this thread
200
+ * <info>Threads created before July 1, 2022 may have an inaccurate count.
201
+ * If you need an approximate value higher than that, use `ThreadChannel#messages.cache.size`</info>
202
+ *
203
+ * @type {?number}
204
+ */
205
+ this.messageCount = data.message_count;
206
+ } else {
207
+ this.messageCount ??= null;
208
+ }
209
+
210
+ if ('member_count' in data) {
211
+ /**
212
+ * The approximate count of users in this thread
213
+ * <info>This stops counting at 50. If you need an approximate value higher than that, use
214
+ * `ThreadChannel#members.cache.size`</info>
215
+ *
216
+ * @type {?number}
217
+ */
218
+ this.memberCount = data.member_count;
219
+ } else {
220
+ this.memberCount ??= null;
221
+ }
222
+
223
+ if ('total_message_sent' in data) {
224
+ /**
225
+ * The number of messages ever sent in a thread, similar to {@link ThreadChannel#messageCount} except it
226
+ * will not decrement whenever a message is deleted
227
+ *
228
+ * @type {?number}
229
+ */
230
+ this.totalMessageSent = data.total_message_sent;
231
+ } else {
232
+ this.totalMessageSent ??= null;
233
+ }
234
+
235
+ if (data.member && this.client.user) this.members._add({ user_id: this.client.user.id, ...data.member });
236
+ if (data.messages) for (const message of data.messages) this.messages._add(message);
237
+
238
+ if ('applied_tags' in data) {
239
+ /**
240
+ * The tags applied to this thread
241
+ *
242
+ * @type {Snowflake[]}
243
+ */
244
+ this.appliedTags = data.applied_tags;
245
+ } else {
246
+ this.appliedTags ??= [];
247
+ }
248
+ }
249
+
250
+ /**
251
+ * The timestamp when this thread was created. This isn't available for threads
252
+ * created before 2022-01-09
253
+ *
254
+ * @type {?number}
255
+ * @readonly
256
+ */
257
+ get createdTimestamp() {
258
+ return this._createdTimestamp;
259
+ }
260
+
261
+ /**
262
+ * A collection of associated guild member objects of this thread's members
263
+ *
264
+ * @type {Collection<Snowflake, GuildMember>}
265
+ * @readonly
266
+ */
267
+ get guildMembers() {
268
+ return this.members.cache.mapValues(member => member.guildMember);
269
+ }
270
+
271
+ /**
272
+ * The time at which this thread's archive status was last changed
273
+ * <info>If the thread was never archived or unarchived, this is the time at which the thread was created</info>
274
+ *
275
+ * @type {?Date}
276
+ * @readonly
277
+ */
278
+ get archivedAt() {
279
+ return this.archiveTimestamp && new Date(this.archiveTimestamp);
280
+ }
281
+
282
+ /**
283
+ * The time the thread was created at
284
+ *
285
+ * @type {?Date}
286
+ * @readonly
287
+ */
288
+ get createdAt() {
289
+ return this.createdTimestamp && new Date(this.createdTimestamp);
290
+ }
291
+
292
+ /**
293
+ * The parent channel of this thread
294
+ *
295
+ * @type {?(AnnouncementChannel|TextChannel|ForumChannel|MediaChannel)}
296
+ * @readonly
297
+ */
298
+ get parent() {
299
+ return this.guild.channels.resolve(this.parentId);
300
+ }
301
+
302
+ /**
303
+ * Makes the client user join the thread.
304
+ *
305
+ * @returns {Promise<ThreadChannel>}
306
+ */
307
+ async join() {
308
+ await this.members.add('@me');
309
+ return this;
310
+ }
311
+
312
+ /**
313
+ * Makes the client user leave the thread.
314
+ *
315
+ * @returns {Promise<ThreadChannel>}
316
+ */
317
+ async leave() {
318
+ await this.members.remove('@me');
319
+ return this;
320
+ }
321
+
322
+ /**
323
+ * Gets the overall set of permissions for a member or role in this thread's parent channel, taking overwrites into
324
+ * account.
325
+ *
326
+ * @param {UserResolvable|RoleResolvable} memberOrRole The member or role to obtain the overall permissions for
327
+ * @param {boolean} [checkAdmin=true] Whether having the {@link PermissionFlagsBits.Administrator} permission
328
+ * will return all permissions
329
+ * @returns {?Readonly<PermissionsBitField>}
330
+ */
331
+ permissionsFor(memberOrRole, checkAdmin) {
332
+ return this.parent?.permissionsFor(memberOrRole, checkAdmin) ?? null;
333
+ }
334
+
335
+ /**
336
+ * Options used to fetch a thread owner.
337
+ *
338
+ * @typedef {BaseFetchOptions} FetchThreadOwnerOptions
339
+ * @property {boolean} [withMember] Whether to also return the guild member associated with this thread member
340
+ */
341
+
342
+ /**
343
+ * Fetches the owner of this thread. If the thread member object isn't needed,
344
+ * use {@link ThreadChannel#ownerId} instead.
345
+ *
346
+ * @param {FetchThreadOwnerOptions} [options] Options for fetching the owner
347
+ * @returns {Promise<ThreadMember>}
348
+ */
349
+ async fetchOwner(options) {
350
+ return this.members._fetchSingle({ ...options, member: this.ownerId });
351
+ }
352
+
353
+ /**
354
+ * Fetches the message that started this thread, if any.
355
+ * <info>The `Promise` will reject if the original message in a forum post is deleted
356
+ * or when the original message in the parent channel is deleted.
357
+ * If you just need the id of that message, use {@link BaseChannel#id} instead.</info>
358
+ *
359
+ * @param {BaseFetchOptions} [options] Additional options for this fetch
360
+ * @returns {Promise<?Message<true>>}
361
+ */
362
+ async fetchStarterMessage(options) {
363
+ const channel = this.parent instanceof getThreadOnlyChannel() ? this : this.parent;
364
+ return channel?.messages.fetch({ message: this.id, ...options }) ?? null;
365
+ }
366
+
367
+ /**
368
+ * The options used to edit a thread channel
369
+ *
370
+ * @typedef {Object} ThreadEditOptions
371
+ * @property {string} [name] The new name for the thread
372
+ * @property {boolean} [archived] Whether the thread is archived
373
+ * @property {ThreadAutoArchiveDuration} [autoArchiveDuration] The amount of time after which the thread
374
+ * should automatically archive in case of no recent activity
375
+ * @property {number} [rateLimitPerUser] The rate limit per user (slowmode) for the thread in seconds
376
+ * @property {boolean} [locked] Whether the thread is locked
377
+ * @property {boolean} [invitable] Whether non-moderators can add other non-moderators to a thread
378
+ * <info>Can only be edited on {@link ChannelType.PrivateThread}</info>
379
+ * @property {Snowflake[]} [appliedTags] The tags to apply to the thread
380
+ * @property {ChannelFlagsResolvable} [flags] The flags to set on the channel
381
+ * @property {string} [reason] Reason for editing the thread
382
+ */
383
+
384
+ /**
385
+ * Edits this thread.
386
+ *
387
+ * @param {ThreadEditOptions} options The options to provide
388
+ * @returns {Promise<ThreadChannel>}
389
+ * @example
390
+ * // Edit a thread
391
+ * thread.edit({ name: 'new-thread' })
392
+ * .then(editedThread => console.log(editedThread))
393
+ * .catch(console.error);
394
+ */
395
+ async edit(options) {
396
+ const newData = await this.client.rest.patch(Routes.channel(this.id), {
397
+ body: {
398
+ name: options.name,
399
+ archived: options.archived,
400
+ auto_archive_duration: options.autoArchiveDuration,
401
+ rate_limit_per_user: options.rateLimitPerUser,
402
+ locked: options.locked,
403
+ invitable: this.type === ChannelType.PrivateThread ? options.invitable : undefined,
404
+ applied_tags: options.appliedTags,
405
+ flags: 'flags' in options ? ChannelFlagsBitField.resolve(options.flags) : undefined,
406
+ },
407
+ reason: options.reason,
408
+ });
409
+
410
+ return this.client.actions.ChannelUpdate.handle(newData).updated;
411
+ }
412
+
413
+ /**
414
+ * Sets whether the thread is archived.
415
+ *
416
+ * @param {boolean} [archived=true] Whether the thread is archived
417
+ * @param {string} [reason] Reason for archiving or unarchiving
418
+ * @returns {Promise<ThreadChannel>}
419
+ * @example
420
+ * // Archive the thread
421
+ * thread.setArchived(true)
422
+ * .then(newThread => console.log(`Thread is now ${newThread.archived ? 'archived' : 'active'}`))
423
+ * .catch(console.error);
424
+ */
425
+ async setArchived(archived = true, reason = undefined) {
426
+ return this.edit({ archived, reason });
427
+ }
428
+
429
+ /**
430
+ * Sets the duration after which the thread will automatically archive in case of no recent activity.
431
+ *
432
+ * @param {ThreadAutoArchiveDuration} autoArchiveDuration The amount of time after which the thread
433
+ * should automatically archive in case of no recent activity
434
+ * @param {string} [reason] Reason for changing the auto archive duration
435
+ * @returns {Promise<ThreadChannel>}
436
+ * @example
437
+ * // Set the thread's auto archive time to 1 hour
438
+ * thread.setAutoArchiveDuration(ThreadAutoArchiveDuration.OneHour)
439
+ * .then(newThread => {
440
+ * console.log(`Thread will now archive after ${newThread.autoArchiveDuration} minutes of inactivity`);
441
+ * });
442
+ * .catch(console.error);
443
+ */
444
+ async setAutoArchiveDuration(autoArchiveDuration, reason) {
445
+ return this.edit({ autoArchiveDuration, reason });
446
+ }
447
+
448
+ /**
449
+ * Sets whether members without the {@link PermissionFlagsBits.ManageThreads} permission
450
+ * can invite other members to this thread.
451
+ *
452
+ * @param {boolean} [invitable=true] Whether non-moderators can invite non-moderators to this thread
453
+ * @param {string} [reason] Reason for changing invite
454
+ * @returns {Promise<ThreadChannel>}
455
+ */
456
+ async setInvitable(invitable = true, reason = undefined) {
457
+ if (this.type !== ChannelType.PrivateThread) {
458
+ throw new DiscordjsRangeError(ErrorCodes.ThreadInvitableType, this.type);
459
+ }
460
+
461
+ return this.edit({ invitable, reason });
462
+ }
463
+
464
+ /**
465
+ * Sets whether the thread can be **unarchived** by anyone with the
466
+ * {@link PermissionFlagsBits.SendMessages} permission. When a thread is locked, only members with the
467
+ * {@link PermissionFlagsBits.ManageThreads} permission can unarchive it.
468
+ *
469
+ * @param {boolean} [locked=true] Whether the thread is locked
470
+ * @param {string} [reason] Reason for locking or unlocking the thread
471
+ * @returns {Promise<ThreadChannel>}
472
+ * @example
473
+ * // Set the thread to locked
474
+ * thread.setLocked(true)
475
+ * .then(newThread => console.log(`Thread is now ${newThread.locked ? 'locked' : 'unlocked'}`))
476
+ * .catch(console.error);
477
+ */
478
+ async setLocked(locked = true, reason = undefined) {
479
+ return this.edit({ locked, reason });
480
+ }
481
+
482
+ /**
483
+ * Sets a new name for this thread.
484
+ *
485
+ * @param {string} name The new name for the thread
486
+ * @param {string} [reason] Reason for changing the thread's name
487
+ * @returns {Promise<ThreadChannel>}
488
+ * @example
489
+ * // Change the thread's name
490
+ * thread.setName('not_general')
491
+ * .then(newThread => console.log(`Thread's new name is ${newThread.name}`))
492
+ * .catch(console.error);
493
+ */
494
+ async setName(name, reason) {
495
+ return this.edit({ name, reason });
496
+ }
497
+
498
+ /**
499
+ * Sets the rate limit per user (slowmode) for this thread.
500
+ *
501
+ * @param {number} rateLimitPerUser The new rate limit in seconds
502
+ * @param {string} [reason] Reason for changing the thread's rate limit
503
+ * @returns {Promise<ThreadChannel>}
504
+ */
505
+ async setRateLimitPerUser(rateLimitPerUser, reason) {
506
+ return this.edit({ rateLimitPerUser, reason });
507
+ }
508
+
509
+ /**
510
+ * Set the applied tags for this channel (only applicable to forum threads)
511
+ *
512
+ * @param {Snowflake[]} appliedTags The tags to set for this channel
513
+ * @param {string} [reason] Reason for changing the thread's applied tags
514
+ * @returns {Promise<ThreadChannel>}
515
+ */
516
+ async setAppliedTags(appliedTags, reason) {
517
+ return this.edit({ appliedTags, reason });
518
+ }
519
+
520
+ /**
521
+ * Pins this thread from the forum channel (only applicable to forum threads).
522
+ *
523
+ * @param {string} [reason] Reason for pinning
524
+ * @returns {Promise<ThreadChannel>}
525
+ */
526
+ async pin(reason) {
527
+ return this.edit({ flags: this.flags.add(ChannelFlags.Pinned), reason });
528
+ }
529
+
530
+ /**
531
+ * Unpins this thread from the forum channel (only applicable to forum threads).
532
+ *
533
+ * @param {string} [reason] Reason for unpinning
534
+ * @returns {Promise<ThreadChannel>}
535
+ */
536
+ async unpin(reason) {
537
+ return this.edit({ flags: this.flags.remove(ChannelFlags.Pinned), reason });
538
+ }
539
+
540
+ /**
541
+ * Whether the client user is a member of the thread.
542
+ *
543
+ * @type {boolean}
544
+ * @readonly
545
+ */
546
+ get joined() {
547
+ return this.members.cache.has(this.client.user?.id);
548
+ }
549
+
550
+ /**
551
+ * Whether the thread is editable by the client user (name, archived, autoArchiveDuration)
552
+ *
553
+ * @type {boolean}
554
+ * @readonly
555
+ */
556
+ get editable() {
557
+ return (
558
+ (this.ownerId === this.client.user.id && (this.type !== ChannelType.PrivateThread || this.joined)) ||
559
+ this.manageable
560
+ );
561
+ }
562
+
563
+ /**
564
+ * Whether the thread is joinable by the client user
565
+ *
566
+ * @type {boolean}
567
+ * @readonly
568
+ */
569
+ get joinable() {
570
+ return (
571
+ !this.archived &&
572
+ !this.joined &&
573
+ this.permissionsFor(this.client.user)?.has(
574
+ this.type === ChannelType.PrivateThread ? PermissionFlagsBits.ManageThreads : PermissionFlagsBits.ViewChannel,
575
+ false,
576
+ )
577
+ );
578
+ }
579
+
580
+ /**
581
+ * Whether the thread is manageable by the client user, for deleting or editing rateLimitPerUser or locked.
582
+ *
583
+ * @type {boolean}
584
+ * @readonly
585
+ */
586
+ get manageable() {
587
+ const permissions = this.permissionsFor(this.client.user);
588
+ if (!permissions) return false;
589
+ // This flag allows managing even if timed out
590
+ if (permissions.has(PermissionFlagsBits.Administrator, false)) return true;
591
+
592
+ return (
593
+ this.guild.members.me.communicationDisabledUntilTimestamp < Date.now() &&
594
+ permissions.has(PermissionFlagsBits.ManageThreads, false)
595
+ );
596
+ }
597
+
598
+ /**
599
+ * Whether the thread is viewable by the client user
600
+ *
601
+ * @type {boolean}
602
+ * @readonly
603
+ */
604
+ get viewable() {
605
+ const permissions = this.permissionsFor(this.client.user);
606
+ if (!permissions) return false;
607
+ return permissions.has(PermissionFlagsBits.ViewChannel, false);
608
+ }
609
+
610
+ /**
611
+ * Whether the client user can send messages in this thread
612
+ *
613
+ * @type {boolean}
614
+ * @readonly
615
+ */
616
+ get sendable() {
617
+ const permissions = this.permissionsFor(this.client.user);
618
+ if (!permissions) return false;
619
+ // This flag allows sending even if timed out
620
+ if (permissions.has(PermissionFlagsBits.Administrator, false)) return true;
621
+
622
+ return (
623
+ !(this.archived && this.locked && !this.manageable) &&
624
+ (this.type !== ChannelType.PrivateThread || this.joined || this.manageable) &&
625
+ permissions.has(PermissionFlagsBits.SendMessagesInThreads, false) &&
626
+ this.guild.members.me.communicationDisabledUntilTimestamp < Date.now()
627
+ );
628
+ }
629
+
630
+ /**
631
+ * Whether the thread is unarchivable by the client user
632
+ *
633
+ * @type {boolean}
634
+ * @readonly
635
+ */
636
+ get unarchivable() {
637
+ return this.archived && this.sendable && (!this.locked || this.manageable);
638
+ }
639
+
640
+ /**
641
+ * Deletes this thread.
642
+ *
643
+ * @param {string} [reason] Reason for deleting this thread
644
+ * @returns {Promise<ThreadChannel>}
645
+ * @example
646
+ * // Delete the thread
647
+ * thread.delete('cleaning out old threads')
648
+ * .then(deletedThread => console.log(deletedThread))
649
+ * .catch(console.error);
650
+ */
651
+ async delete(reason) {
652
+ await this.guild.channels.delete(this.id, reason);
653
+ return this;
654
+ }
655
+
656
+ // These are here only for documentation purposes - they are implemented by TextBasedChannel
657
+
658
+ /* eslint-disable getter-return */
659
+ get lastMessage() {}
660
+
661
+ get lastPinAt() {}
662
+
663
+ send() {}
664
+
665
+ sendTyping() {}
666
+
667
+ createMessageCollector() {}
668
+
669
+ awaitMessages() {}
670
+
671
+ createMessageComponentCollector() {}
672
+
673
+ awaitMessageComponent() {}
674
+
675
+ bulkDelete() {}
676
+ // Doesn't work on Thread channels; setRateLimitPerUser() {}
677
+ // Doesn't work on Thread channels; setNSFW() {}
678
+ }
679
+
680
+ TextBasedChannel.applyToClass(ThreadChannel, ['fetchWebhooks', 'setRateLimitPerUser', 'setNSFW']);