@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,643 @@
1
+ import { PermissionFlagsBits } from 'discord-api-types/v10';
2
+ import { DiscordjsError, ErrorCodes } from '../errors/index.js';
3
+ import { GuildMemberRoleManager } from '../managers/GuildMemberRoleManager.js';
4
+ import { GuildMemberFlagsBitField } from '../util/GuildMemberFlagsBitField.js';
5
+ import { PermissionsBitField } from '../util/PermissionsBitField.js';
6
+ import { Base } from './Base.js';
7
+ import { VoiceState } from './VoiceState.js';
8
+
9
+ /**
10
+ * Represents a member of a guild on Discord.
11
+ *
12
+ * @extends {Base}
13
+ */
14
+ export class GuildMember extends Base {
15
+ public client: any;
16
+ public guild: any;
17
+ public premiumSinceTimestamp: any;
18
+ public nickname: any;
19
+ public pending: any;
20
+ public communicationDisabledUntilTimestamp: any;
21
+ public user: any;
22
+ public avatar: any;
23
+ public banner: any;
24
+ public joinedTimestamp: any;
25
+ public _roles: any;
26
+ public flags: any;
27
+ public avatarDecorationData: any;
28
+ constructor(client, data, guild) {
29
+ super(client);
30
+
31
+ /**
32
+ * The guild that this member is part of
33
+ *
34
+ * @type {Guild}
35
+ */
36
+ this.guild = guild;
37
+
38
+ /**
39
+ * The last timestamp this member started boosting the guild
40
+ *
41
+ * @type {?number}
42
+ */
43
+ this.premiumSinceTimestamp = null;
44
+
45
+ /**
46
+ * The nickname of this member, if they have one
47
+ *
48
+ * @type {?string}
49
+ */
50
+ this.nickname = null;
51
+
52
+ /**
53
+ * Whether this member has yet to pass the guild's membership gate
54
+ *
55
+ * @type {?boolean}
56
+ */
57
+ this.pending = null;
58
+
59
+ /**
60
+ * The timestamp this member's timeout will be removed
61
+ *
62
+ * @type {?number}
63
+ */
64
+ this.communicationDisabledUntilTimestamp = null;
65
+
66
+ /**
67
+ * The role ids of the member
68
+ *
69
+ * @name GuildMember#_roles
70
+ * @type {Snowflake[]}
71
+ * @private
72
+ */
73
+ Object.defineProperty(this, '_roles', { value: [], writable: true });
74
+
75
+ this._patch(data);
76
+ }
77
+
78
+ _patch(data) {
79
+ if ('user' in data) {
80
+ /**
81
+ * The user that this guild member instance represents
82
+ *
83
+ * @type {?User}
84
+ */
85
+ this.user = this.client.users._add(data.user, true);
86
+ }
87
+
88
+ if ('nick' in data) this.nickname = data.nick;
89
+ if ('avatar' in data) {
90
+ /**
91
+ * The guild member's avatar hash
92
+ *
93
+ * @type {?string}
94
+ */
95
+ this.avatar = data.avatar;
96
+ } else if (typeof this.avatar !== 'string') {
97
+ this.avatar = null;
98
+ }
99
+
100
+ if ('banner' in data) {
101
+ /**
102
+ * The guild member's banner hash.
103
+ *
104
+ * @type {?string}
105
+ */
106
+ this.banner = data.banner;
107
+ } else {
108
+ this.banner ??= null;
109
+ }
110
+
111
+ if ('joined_at' in data) {
112
+ /**
113
+ * The timestamp the member joined the guild at
114
+ *
115
+ * @type {?number}
116
+ */
117
+ this.joinedTimestamp = data.joined_at && Date.parse(data.joined_at);
118
+ } else {
119
+ this.joinedTimestamp ??= null;
120
+ }
121
+
122
+ if ('premium_since' in data) {
123
+ this.premiumSinceTimestamp = data.premium_since ? Date.parse(data.premium_since) : null;
124
+ }
125
+
126
+ if ('roles' in data) this._roles = data.roles;
127
+
128
+ if ('pending' in data) {
129
+ this.pending = data.pending;
130
+ } else if (!this.partial) {
131
+ // See https://github.com/ovencord/ovencord/issues/6546 for more info.
132
+ this.pending ??= false;
133
+ }
134
+
135
+ if ('communication_disabled_until' in data) {
136
+ this.communicationDisabledUntilTimestamp =
137
+ data.communication_disabled_until && Date.parse(data.communication_disabled_until);
138
+ }
139
+
140
+ if ('flags' in data) {
141
+ /**
142
+ * The flags of this member
143
+ *
144
+ * @type {Readonly<GuildMemberFlagsBitField>}
145
+ */
146
+ this.flags = new GuildMemberFlagsBitField(data.flags).freeze();
147
+ } else {
148
+ this.flags ??= new GuildMemberFlagsBitField().freeze();
149
+ }
150
+
151
+ if (data.avatar_decoration_data) {
152
+ /**
153
+ * The member avatar decoration's data
154
+ *
155
+ * @type {?AvatarDecorationData}
156
+ */
157
+ this.avatarDecorationData = {
158
+ asset: data.avatar_decoration_data.asset,
159
+ skuId: data.avatar_decoration_data.sku_id,
160
+ };
161
+ } else {
162
+ this.avatarDecorationData = null;
163
+ }
164
+ }
165
+
166
+ _clone() {
167
+ const clone = super._clone();
168
+ clone._roles = this._roles.slice();
169
+ return clone;
170
+ }
171
+
172
+ /**
173
+ * Whether this GuildMember is a partial
174
+ *
175
+ * @type {boolean}
176
+ * @readonly
177
+ */
178
+ get partial() {
179
+ return this.joinedTimestamp === null;
180
+ }
181
+
182
+ /**
183
+ * A manager for the roles belonging to this member
184
+ *
185
+ * @type {GuildMemberRoleManager}
186
+ * @readonly
187
+ */
188
+ get roles() {
189
+ return new GuildMemberRoleManager(this);
190
+ }
191
+
192
+ /**
193
+ * The voice state of this member
194
+ *
195
+ * @type {VoiceState}
196
+ * @readonly
197
+ */
198
+ get voice() {
199
+ return this.guild.voiceStates.cache.get(this.id) ?? new VoiceState(this.guild, { user_id: this.id });
200
+ }
201
+
202
+ /**
203
+ * A link to the member's guild avatar.
204
+ *
205
+ * @param {ImageURLOptions} [options={}] Options for the image URL
206
+ * @returns {?string}
207
+ */
208
+ avatarURL(options = {}) {
209
+ return this.avatar && this.client.rest.cdn.guildMemberAvatar(this.guild.id, this.id, this.avatar, options);
210
+ }
211
+
212
+ /**
213
+ * A link to the member's avatar decoration.
214
+ *
215
+ * @returns {?string}
216
+ */
217
+ avatarDecorationURL() {
218
+ return this.avatarDecorationData ? this.client.rest.cdn.avatarDecoration(this.avatarDecorationData.asset) : null;
219
+ }
220
+
221
+ /**
222
+ * A link to the member's banner.
223
+ *
224
+ * @param {ImageURLOptions} [options={}] Options for the banner URL
225
+ * @returns {?string}
226
+ */
227
+ bannerURL(options = {}) {
228
+ return this.banner && this.client.rest.cdn.guildMemberBanner(this.guild.id, this.id, this.banner, options);
229
+ }
230
+
231
+ /**
232
+ * A link to the member's guild avatar if they have one.
233
+ * Otherwise, a link to their {@link User#displayAvatarURL} will be returned.
234
+ *
235
+ * @param {ImageURLOptions} [options={}] Options for the image URL
236
+ * @returns {string}
237
+ */
238
+ displayAvatarURL(options) {
239
+ return this.avatarURL(options) ?? this.user.displayAvatarURL(options);
240
+ }
241
+
242
+ /**
243
+ * A link to the member's guild banner if they have one.
244
+ * Otherwise, a link to their {@link User#bannerURL} will be returned.
245
+ *
246
+ * @param {ImageURLOptions} [options={}] Options for the image URL
247
+ * @returns {?string}
248
+ */
249
+ displayBannerURL(options) {
250
+ return this.bannerURL(options) ?? this.user.bannerURL(options);
251
+ }
252
+
253
+ /**
254
+ * A link to the member's guild avatar decoration if they have one.
255
+ * Otherwise, a link to their {@link User#avatarDecorationURL} will be returned.
256
+ *
257
+ * @returns {?string}
258
+ */
259
+ displayAvatarDecorationURL() {
260
+ return this.avatarDecorationURL() ?? this.user.avatarDecorationURL();
261
+ }
262
+
263
+ /**
264
+ * The time this member joined the guild
265
+ *
266
+ * @type {?Date}
267
+ * @readonly
268
+ */
269
+ get joinedAt() {
270
+ return this.joinedTimestamp && new Date(this.joinedTimestamp);
271
+ }
272
+
273
+ /**
274
+ * The time this member's timeout will be removed
275
+ *
276
+ * @type {?Date}
277
+ * @readonly
278
+ */
279
+ get communicationDisabledUntil() {
280
+ return this.communicationDisabledUntilTimestamp && new Date(this.communicationDisabledUntilTimestamp);
281
+ }
282
+
283
+ /**
284
+ * The last time this member started boosting the guild
285
+ *
286
+ * @type {?Date}
287
+ * @readonly
288
+ */
289
+ get premiumSince() {
290
+ return this.premiumSinceTimestamp && new Date(this.premiumSinceTimestamp);
291
+ }
292
+
293
+ /**
294
+ * The presence of this guild member
295
+ *
296
+ * @type {?Presence}
297
+ * @readonly
298
+ */
299
+ get presence() {
300
+ return this.guild.presences.cache.get(this.id) ?? null;
301
+ }
302
+
303
+ /**
304
+ * The displayed role color of this member in base 10
305
+ *
306
+ * @type {number}
307
+ * @readonly
308
+ */
309
+ get displayColor() {
310
+ return this.roles.color?.colors.primaryColor ?? 0;
311
+ }
312
+
313
+ /**
314
+ * The displayed role color of this member in hexadecimal
315
+ *
316
+ * @type {string}
317
+ * @readonly
318
+ */
319
+ get displayHexColor() {
320
+ return this.roles.color?.hexColor ?? '#000000';
321
+ }
322
+
323
+ /**
324
+ * The member's id
325
+ *
326
+ * @type {Snowflake}
327
+ * @readonly
328
+ */
329
+ get id() {
330
+ return this.user.id;
331
+ }
332
+
333
+ /**
334
+ * The DM between the client's user and this member
335
+ *
336
+ * @type {?DMChannel}
337
+ * @readonly
338
+ */
339
+ get dmChannel() {
340
+ return this.client.users.dmChannel(this.id);
341
+ }
342
+
343
+ /**
344
+ * The nickname of this member, or their user display name if they don't have one
345
+ *
346
+ * @type {?string}
347
+ * @readonly
348
+ */
349
+ get displayName() {
350
+ return this.nickname ?? this.user.displayName;
351
+ }
352
+
353
+ /**
354
+ * The overall set of permissions for this member, taking only roles and owner status into account
355
+ *
356
+ * @type {Readonly<PermissionsBitField>}
357
+ * @readonly
358
+ */
359
+ get permissions() {
360
+ if (this.user.id === this.guild.ownerId) return new PermissionsBitField(PermissionsBitField.All).freeze();
361
+ return new PermissionsBitField(this.roles.cache.map(role => role.permissions)).freeze();
362
+ }
363
+
364
+ /**
365
+ * Whether the client user is above this user in the hierarchy, according to role position and guild ownership.
366
+ * This is a prerequisite for many moderative actions.
367
+ *
368
+ * @type {boolean}
369
+ * @readonly
370
+ */
371
+ get manageable() {
372
+ if (this.user.id === this.guild.ownerId) return false;
373
+ if (this.user.id === this.client.user.id) return false;
374
+ if (!this.guild.members.me) throw new DiscordjsError(ErrorCodes.GuildUncachedMe);
375
+ return this.guild.members.me.roles.highest.comparePositionTo(this.roles.highest) > 0;
376
+ }
377
+
378
+ /**
379
+ * Whether this member is kickable by the client user
380
+ *
381
+ * @type {boolean}
382
+ * @readonly
383
+ */
384
+ get kickable() {
385
+ if (!this.guild.members.me) throw new DiscordjsError(ErrorCodes.GuildUncachedMe);
386
+ return this.manageable && this.guild.members.me.permissions.has(PermissionFlagsBits.KickMembers);
387
+ }
388
+
389
+ /**
390
+ * Whether this member is bannable by the client user
391
+ *
392
+ * @type {boolean}
393
+ * @readonly
394
+ */
395
+ get bannable() {
396
+ if (!this.guild.members.me) throw new DiscordjsError(ErrorCodes.GuildUncachedMe);
397
+ return this.manageable && this.guild.members.me.permissions.has(PermissionFlagsBits.BanMembers);
398
+ }
399
+
400
+ /**
401
+ * Whether this member is moderatable by the client user
402
+ *
403
+ * @type {boolean}
404
+ * @readonly
405
+ */
406
+ get moderatable() {
407
+ return (
408
+ !this.permissions.has(PermissionFlagsBits.Administrator) &&
409
+ this.manageable &&
410
+ (this.guild.members.me?.permissions.has(PermissionFlagsBits.ModerateMembers) ?? false)
411
+ );
412
+ }
413
+
414
+ /**
415
+ * Whether this member is currently timed out
416
+ *
417
+ * @returns {boolean}
418
+ */
419
+ isCommunicationDisabled() {
420
+ return this.communicationDisabledUntilTimestamp > Date.now();
421
+ }
422
+
423
+ /**
424
+ * Returns `channel.permissionsFor(guildMember)`. Returns permissions for a member in a guild channel,
425
+ * taking into account roles and permission overwrites.
426
+ *
427
+ * @param {GuildChannelResolvable} channel The guild channel to use as context
428
+ * @returns {Readonly<PermissionsBitField>}
429
+ */
430
+ permissionsIn(channel) {
431
+ const resolvedChannel = this.guild.channels.resolve(channel);
432
+ if (!resolvedChannel) throw new DiscordjsError(ErrorCodes.GuildChannelResolve);
433
+ return resolvedChannel.permissionsFor(this);
434
+ }
435
+
436
+ /**
437
+ * Edits this member.
438
+ *
439
+ * @param {GuildMemberEditOptions} options The options to provide
440
+ * @returns {Promise<GuildMember>}
441
+ */
442
+ async edit(options) {
443
+ return this.guild.members.edit(this, options);
444
+ }
445
+
446
+ /**
447
+ * Sets the flags for this member.
448
+ *
449
+ * @param {GuildMemberFlagsResolvable} flags The flags to set
450
+ * @param {string} [reason] Reason for setting the flags
451
+ * @returns {Promise<GuildMember>}
452
+ */
453
+ async setFlags(flags, reason) {
454
+ return this.edit({ flags, reason });
455
+ }
456
+
457
+ /**
458
+ * Sets the nickname for this member.
459
+ *
460
+ * @param {?string} nick The nickname for the guild member, or `null` if you want to reset their nickname
461
+ * @param {string} [reason] Reason for setting the nickname
462
+ * @returns {Promise<GuildMember>}
463
+ * @example
464
+ * // Set a nickname for a guild member
465
+ * guildMember.setNickname('cool nickname', 'Needed a new nickname')
466
+ * .then(member => console.log(`Set nickname of ${member.user.username}`))
467
+ * .catch(console.error);
468
+ * @example
469
+ * // Remove a nickname for a guild member
470
+ * guildMember.setNickname(null, 'No nicknames allowed!')
471
+ * .then(member => console.log(`Removed nickname for ${member.user.username}`))
472
+ * .catch(console.error);
473
+ */
474
+ async setNickname(nick, reason) {
475
+ return this.user.id === this.client.user.id
476
+ ? this.guild.members.editMe({ nick, reason })
477
+ : this.edit({ nick, reason });
478
+ }
479
+
480
+ /**
481
+ * Creates a DM channel between the client and this member.
482
+ *
483
+ * @param {boolean} [force=false] Whether to skip the cache check and request the API
484
+ * @returns {Promise<DMChannel>}
485
+ */
486
+ async createDM(force = false) {
487
+ return this.user.createDM(force);
488
+ }
489
+
490
+ /**
491
+ * Deletes any DMs with this member.
492
+ *
493
+ * @returns {Promise<DMChannel>}
494
+ */
495
+ async deleteDM() {
496
+ return this.user.deleteDM();
497
+ }
498
+
499
+ /**
500
+ * Kicks this member from the guild.
501
+ *
502
+ * @param {string} [reason] Reason for kicking user
503
+ * @returns {Promise<void>}
504
+ */
505
+ async kick(reason) {
506
+ await this.guild.members.kick(this, reason);
507
+ }
508
+
509
+ /**
510
+ * Bans this guild member.
511
+ *
512
+ * @param {BanOptions} [options] Options for the ban
513
+ * @returns {Promise<void>}
514
+ * @example
515
+ * // Ban a guild member, deleting a week's worth of messages
516
+ * await guildMember.ban({ deleteMessageSeconds: 60 * 60 * 24 * 7, reason: 'They deserved it' });
517
+ */
518
+ async ban(options) {
519
+ await this.guild.bans.create(this, options);
520
+ }
521
+
522
+ /**
523
+ * Times this guild member out.
524
+ *
525
+ * @param {?DateResolvable} communicationDisabledUntil The date or timestamp
526
+ * for the member's communication to be disabled until. Provide `null` to remove the timeout.
527
+ * @param {string} [reason] The reason for this timeout.
528
+ * @returns {Promise<GuildMember>}
529
+ * @example
530
+ * // Time a guild member out for 5 minutes
531
+ * guildMember.disableCommunicationUntil(Date.now() + (5 * 60 * 1000), 'They deserved it')
532
+ * .then(console.log)
533
+ * .catch(console.error);
534
+ * @example
535
+ * // Remove the timeout of a guild member
536
+ * guildMember.disableCommunicationUntil(null)
537
+ * .then(member => console.log(`Removed timeout for ${member.displayName}`))
538
+ * .catch(console.error);
539
+ */
540
+ async disableCommunicationUntil(communicationDisabledUntil, reason) {
541
+ return this.edit({ communicationDisabledUntil, reason });
542
+ }
543
+
544
+ /**
545
+ * Times this guild member out.
546
+ *
547
+ * @param {?number} timeout The duration in milliseconds
548
+ * for the member's communication to be disabled. Provide `null` to remove the timeout.
549
+ * @param {string} [reason] The reason for this timeout.
550
+ * @returns {Promise<GuildMember>}
551
+ * @example
552
+ * // Time a guild member out for 5 minutes
553
+ * guildMember.timeout(5 * 60 * 1000, 'They deserved it')
554
+ * .then(console.log)
555
+ * .catch(console.error);
556
+ */
557
+ async timeout(timeout, reason) {
558
+ return this.disableCommunicationUntil(timeout && Date.now() + timeout, reason);
559
+ }
560
+
561
+ /**
562
+ * Fetches this GuildMember.
563
+ *
564
+ * @param {boolean} [force=true] Whether to skip the cache check and request the API
565
+ * @returns {Promise<GuildMember>}
566
+ */
567
+ async fetch(force = true) {
568
+ return this.guild.members.fetch({ user: this.id, cache: true, force });
569
+ }
570
+
571
+ /**
572
+ * Sends a message to this user.
573
+ *
574
+ * @param {string|MessagePayload|MessageCreateOptions} options The options to provide
575
+ * @returns {Promise<Message>}
576
+ * @example
577
+ * // Send a direct message
578
+ * guildMember.send('Hello!')
579
+ * .then(message => console.log(`Sent message: ${message.content} to ${guildMember.displayName}`))
580
+ * .catch(console.error);
581
+ */
582
+ async send(options) {
583
+ const dmChannel = await this.createDM();
584
+
585
+ return this.client.channels.createMessage(dmChannel, options);
586
+ }
587
+
588
+ /**
589
+ * Whether this guild member equals another guild member. It compares all properties, so for most
590
+ * comparison it is advisable to just compare `member.id === member2.id` as it is significantly faster
591
+ * and is often what most users need.
592
+ *
593
+ * @param {GuildMember} member The member to compare with
594
+ * @returns {boolean}
595
+ */
596
+ equals(member) {
597
+ return (
598
+ member instanceof this.constructor &&
599
+ this.id === member.id &&
600
+ this.partial === member.partial &&
601
+ this.guild.id === member.guild.id &&
602
+ this.joinedTimestamp === member.joinedTimestamp &&
603
+ this.nickname === member.nickname &&
604
+ this.avatar === member.avatar &&
605
+ this.banner === member.banner &&
606
+ this.pending === member.pending &&
607
+ this.communicationDisabledUntilTimestamp === member.communicationDisabledUntilTimestamp &&
608
+ this.flags.bitfield === member.flags.bitfield &&
609
+ (this._roles === member._roles ||
610
+ (this._roles.length === member._roles.length &&
611
+ this._roles.every((role, index) => role === member._roles[index]))) &&
612
+ this.avatarDecorationData?.asset === member.avatarDecorationData?.asset &&
613
+ this.avatarDecorationData?.skuId === member.avatarDecorationData?.skuId
614
+ );
615
+ }
616
+
617
+ /**
618
+ * When concatenated with a string, this automatically returns the user's mention instead of the GuildMember object.
619
+ *
620
+ * @returns {string}
621
+ * @example
622
+ * // Logs: Hello from <@123456789012345678>!
623
+ * console.log(`Hello from ${member}!`);
624
+ */
625
+ toString() {
626
+ return this.user.toString();
627
+ }
628
+
629
+ toJSON() {
630
+ const json = super.toJSON({
631
+ guild: 'guildId',
632
+ user: 'userId',
633
+ displayName: true,
634
+ roles: true,
635
+ });
636
+ json.avatarURL = this.avatarURL();
637
+ json.bannerURL = this.bannerURL();
638
+ json.displayAvatarURL = this.displayAvatarURL();
639
+ json.displayBannerURL = this.displayBannerURL();
640
+ json.avatarDecorationURL = this.avatarDecorationURL();
641
+ return json;
642
+ }
643
+ }
@@ -0,0 +1,73 @@
1
+ import { Collection } from '@ovencord/collection';
2
+ import { Base } from './Base.js';
3
+ import { GuildOnboardingPrompt } from './GuildOnboardingPrompt.js';
4
+
5
+ /**
6
+ * Represents the onboarding data of a guild.
7
+ *
8
+ * @extends {Base}
9
+ */
10
+ export class GuildOnboarding extends Base {
11
+ public client: any;
12
+ public guildId: any;
13
+ public prompts: any;
14
+ public defaultChannels: any;
15
+ public enabled: any;
16
+ public mode: any;
17
+ constructor(client, data) {
18
+ super(client);
19
+
20
+ /**
21
+ * The id of the guild this onboarding data is for
22
+ *
23
+ * @type {Snowflake}
24
+ */
25
+ this.guildId = data.guild_id;
26
+
27
+ const guild = this.guild;
28
+
29
+ /**
30
+ * The prompts shown during onboarding and in customize community
31
+ *
32
+ * @type {Collection<Snowflake, GuildOnboardingPrompt>}
33
+ */
34
+ this.prompts = data.prompts.reduce(
35
+ (prompts, prompt) => prompts.set(prompt.id, new GuildOnboardingPrompt(client, prompt, this.guildId)),
36
+ new Collection(),
37
+ );
38
+
39
+ /**
40
+ * The ids of the channels that new members get opted into automatically
41
+ *
42
+ * @type {Collection<Snowflake, GuildChannel>}
43
+ */
44
+ this.defaultChannels = data.default_channel_ids.reduce(
45
+ (channels, channelId) => channels.set(channelId, guild.channels.cache.get(channelId)),
46
+ new Collection(),
47
+ );
48
+
49
+ /**
50
+ * Whether onboarding is enabled
51
+ *
52
+ * @type {boolean}
53
+ */
54
+ this.enabled = data.enabled;
55
+
56
+ /**
57
+ * The mode of this onboarding
58
+ *
59
+ * @type {GuildOnboardingMode}
60
+ */
61
+ this.mode = data.mode;
62
+ }
63
+
64
+ /**
65
+ * The guild this onboarding is from
66
+ *
67
+ * @type {Guild}
68
+ * @readonly
69
+ */
70
+ get guild() {
71
+ return this.client.guilds.cache.get(this.guildId);
72
+ }
73
+ }