discord.js-selfbot-v13-new 1.0.0

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 (364) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +124 -0
  3. package/package.json +89 -0
  4. package/src/WebSocket.js +39 -0
  5. package/src/client/BaseClient.js +86 -0
  6. package/src/client/Client.js +934 -0
  7. package/src/client/WebhookClient.js +61 -0
  8. package/src/client/actions/Action.js +116 -0
  9. package/src/client/actions/ActionsManager.js +80 -0
  10. package/src/client/actions/ApplicationCommandPermissionsUpdate.js +34 -0
  11. package/src/client/actions/AutoModerationActionExecution.js +27 -0
  12. package/src/client/actions/AutoModerationRuleCreate.js +28 -0
  13. package/src/client/actions/AutoModerationRuleDelete.js +32 -0
  14. package/src/client/actions/AutoModerationRuleUpdate.js +30 -0
  15. package/src/client/actions/ChannelCreate.js +23 -0
  16. package/src/client/actions/ChannelDelete.js +39 -0
  17. package/src/client/actions/ChannelUpdate.js +43 -0
  18. package/src/client/actions/GuildAuditLogEntryCreate.js +29 -0
  19. package/src/client/actions/GuildBanAdd.js +20 -0
  20. package/src/client/actions/GuildBanRemove.js +25 -0
  21. package/src/client/actions/GuildChannelsPositionUpdate.js +21 -0
  22. package/src/client/actions/GuildDelete.js +65 -0
  23. package/src/client/actions/GuildEmojiCreate.js +20 -0
  24. package/src/client/actions/GuildEmojiDelete.js +21 -0
  25. package/src/client/actions/GuildEmojiUpdate.js +20 -0
  26. package/src/client/actions/GuildEmojisUpdate.js +34 -0
  27. package/src/client/actions/GuildIntegrationsUpdate.js +19 -0
  28. package/src/client/actions/GuildMemberRemove.js +33 -0
  29. package/src/client/actions/GuildMemberUpdate.js +44 -0
  30. package/src/client/actions/GuildRoleCreate.js +25 -0
  31. package/src/client/actions/GuildRoleDelete.js +31 -0
  32. package/src/client/actions/GuildRoleUpdate.js +39 -0
  33. package/src/client/actions/GuildRolesPositionUpdate.js +21 -0
  34. package/src/client/actions/GuildScheduledEventCreate.js +27 -0
  35. package/src/client/actions/GuildScheduledEventDelete.js +31 -0
  36. package/src/client/actions/GuildScheduledEventUpdate.js +30 -0
  37. package/src/client/actions/GuildScheduledEventUserAdd.js +32 -0
  38. package/src/client/actions/GuildScheduledEventUserRemove.js +32 -0
  39. package/src/client/actions/GuildStickerCreate.js +20 -0
  40. package/src/client/actions/GuildStickerDelete.js +21 -0
  41. package/src/client/actions/GuildStickerUpdate.js +20 -0
  42. package/src/client/actions/GuildStickersUpdate.js +34 -0
  43. package/src/client/actions/GuildUpdate.js +33 -0
  44. package/src/client/actions/InviteCreate.js +28 -0
  45. package/src/client/actions/InviteDelete.js +30 -0
  46. package/src/client/actions/MessageCreate.js +50 -0
  47. package/src/client/actions/MessageDelete.js +32 -0
  48. package/src/client/actions/MessageDeleteBulk.js +46 -0
  49. package/src/client/actions/MessagePollVoteAdd.js +33 -0
  50. package/src/client/actions/MessagePollVoteRemove.js +33 -0
  51. package/src/client/actions/MessageReactionAdd.js +68 -0
  52. package/src/client/actions/MessageReactionRemove.js +50 -0
  53. package/src/client/actions/MessageReactionRemoveAll.js +33 -0
  54. package/src/client/actions/MessageReactionRemoveEmoji.js +28 -0
  55. package/src/client/actions/MessageUpdate.js +26 -0
  56. package/src/client/actions/PresenceUpdate.js +50 -0
  57. package/src/client/actions/StageInstanceCreate.js +28 -0
  58. package/src/client/actions/StageInstanceDelete.js +33 -0
  59. package/src/client/actions/StageInstanceUpdate.js +30 -0
  60. package/src/client/actions/ThreadCreate.js +24 -0
  61. package/src/client/actions/ThreadDelete.js +32 -0
  62. package/src/client/actions/ThreadListSync.js +59 -0
  63. package/src/client/actions/ThreadMemberUpdate.js +30 -0
  64. package/src/client/actions/ThreadMembersUpdate.js +34 -0
  65. package/src/client/actions/TypingStart.js +29 -0
  66. package/src/client/actions/UserUpdate.js +35 -0
  67. package/src/client/actions/VoiceStateUpdate.js +50 -0
  68. package/src/client/actions/WebhooksUpdate.js +20 -0
  69. package/src/client/voice/ClientVoiceManager.js +151 -0
  70. package/src/client/voice/VoiceConnection.js +1249 -0
  71. package/src/client/voice/dispatcher/AnnexBDispatcher.js +120 -0
  72. package/src/client/voice/dispatcher/AudioDispatcher.js +145 -0
  73. package/src/client/voice/dispatcher/BaseDispatcher.js +459 -0
  74. package/src/client/voice/dispatcher/VPxDispatcher.js +54 -0
  75. package/src/client/voice/dispatcher/VideoDispatcher.js +68 -0
  76. package/src/client/voice/networking/VoiceUDPClient.js +173 -0
  77. package/src/client/voice/networking/VoiceWebSocket.js +286 -0
  78. package/src/client/voice/player/MediaPlayer.js +321 -0
  79. package/src/client/voice/player/processing/AnnexBNalSplitter.js +244 -0
  80. package/src/client/voice/player/processing/IvfSplitter.js +106 -0
  81. package/src/client/voice/player/processing/PCMInsertSilence.js +37 -0
  82. package/src/client/voice/receiver/PacketHandler.js +260 -0
  83. package/src/client/voice/receiver/Receiver.js +96 -0
  84. package/src/client/voice/receiver/Recorder.js +173 -0
  85. package/src/client/voice/util/Function.js +116 -0
  86. package/src/client/voice/util/PlayInterface.js +122 -0
  87. package/src/client/voice/util/Secretbox.js +64 -0
  88. package/src/client/voice/util/Silence.js +16 -0
  89. package/src/client/voice/util/Socket.js +62 -0
  90. package/src/client/voice/util/VolumeInterface.js +104 -0
  91. package/src/client/websocket/WebSocketManager.js +392 -0
  92. package/src/client/websocket/WebSocketShard.js +907 -0
  93. package/src/client/websocket/handlers/APPLICATION_COMMAND_CREATE.js +18 -0
  94. package/src/client/websocket/handlers/APPLICATION_COMMAND_DELETE.js +20 -0
  95. package/src/client/websocket/handlers/APPLICATION_COMMAND_PERMISSIONS_UPDATE.js +5 -0
  96. package/src/client/websocket/handlers/APPLICATION_COMMAND_UPDATE.js +20 -0
  97. package/src/client/websocket/handlers/AUTO_MODERATION_ACTION_EXECUTION.js +5 -0
  98. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_CREATE.js +5 -0
  99. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_DELETE.js +5 -0
  100. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_UPDATE.js +5 -0
  101. package/src/client/websocket/handlers/CALL_CREATE.js +14 -0
  102. package/src/client/websocket/handlers/CALL_DELETE.js +11 -0
  103. package/src/client/websocket/handlers/CALL_UPDATE.js +11 -0
  104. package/src/client/websocket/handlers/CHANNEL_CREATE.js +5 -0
  105. package/src/client/websocket/handlers/CHANNEL_DELETE.js +5 -0
  106. package/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.js +22 -0
  107. package/src/client/websocket/handlers/CHANNEL_RECIPIENT_ADD.js +19 -0
  108. package/src/client/websocket/handlers/CHANNEL_RECIPIENT_REMOVE.js +16 -0
  109. package/src/client/websocket/handlers/CHANNEL_UPDATE.js +16 -0
  110. package/src/client/websocket/handlers/GUILD_AUDIT_LOG_ENTRY_CREATE.js +5 -0
  111. package/src/client/websocket/handlers/GUILD_BAN_ADD.js +5 -0
  112. package/src/client/websocket/handlers/GUILD_BAN_REMOVE.js +5 -0
  113. package/src/client/websocket/handlers/GUILD_CREATE.js +52 -0
  114. package/src/client/websocket/handlers/GUILD_DELETE.js +5 -0
  115. package/src/client/websocket/handlers/GUILD_EMOJIS_UPDATE.js +5 -0
  116. package/src/client/websocket/handlers/GUILD_INTEGRATIONS_UPDATE.js +5 -0
  117. package/src/client/websocket/handlers/GUILD_MEMBERS_CHUNK.js +39 -0
  118. package/src/client/websocket/handlers/GUILD_MEMBER_ADD.js +20 -0
  119. package/src/client/websocket/handlers/GUILD_MEMBER_REMOVE.js +5 -0
  120. package/src/client/websocket/handlers/GUILD_MEMBER_UPDATE.js +5 -0
  121. package/src/client/websocket/handlers/GUILD_ROLE_CREATE.js +5 -0
  122. package/src/client/websocket/handlers/GUILD_ROLE_DELETE.js +5 -0
  123. package/src/client/websocket/handlers/GUILD_ROLE_UPDATE.js +5 -0
  124. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_CREATE.js +5 -0
  125. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_DELETE.js +5 -0
  126. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_UPDATE.js +5 -0
  127. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_ADD.js +5 -0
  128. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_REMOVE.js +5 -0
  129. package/src/client/websocket/handlers/GUILD_STICKERS_UPDATE.js +5 -0
  130. package/src/client/websocket/handlers/GUILD_UPDATE.js +5 -0
  131. package/src/client/websocket/handlers/INTERACTION_MODAL_CREATE.js +12 -0
  132. package/src/client/websocket/handlers/INVITE_CREATE.js +5 -0
  133. package/src/client/websocket/handlers/INVITE_DELETE.js +5 -0
  134. package/src/client/websocket/handlers/MESSAGE_CREATE.js +5 -0
  135. package/src/client/websocket/handlers/MESSAGE_DELETE.js +5 -0
  136. package/src/client/websocket/handlers/MESSAGE_DELETE_BULK.js +5 -0
  137. package/src/client/websocket/handlers/MESSAGE_POLL_VOTE_ADD.js +5 -0
  138. package/src/client/websocket/handlers/MESSAGE_POLL_VOTE_REMOVE.js +5 -0
  139. package/src/client/websocket/handlers/MESSAGE_REACTION_ADD.js +5 -0
  140. package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE.js +5 -0
  141. package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_ALL.js +5 -0
  142. package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_EMOJI.js +5 -0
  143. package/src/client/websocket/handlers/MESSAGE_UPDATE.js +16 -0
  144. package/src/client/websocket/handlers/PRESENCE_UPDATE.js +5 -0
  145. package/src/client/websocket/handlers/READY.js +121 -0
  146. package/src/client/websocket/handlers/RELATIONSHIP_ADD.js +19 -0
  147. package/src/client/websocket/handlers/RELATIONSHIP_REMOVE.js +17 -0
  148. package/src/client/websocket/handlers/RELATIONSHIP_UPDATE.js +41 -0
  149. package/src/client/websocket/handlers/RESUMED.js +14 -0
  150. package/src/client/websocket/handlers/STAGE_INSTANCE_CREATE.js +5 -0
  151. package/src/client/websocket/handlers/STAGE_INSTANCE_DELETE.js +5 -0
  152. package/src/client/websocket/handlers/STAGE_INSTANCE_UPDATE.js +5 -0
  153. package/src/client/websocket/handlers/THREAD_CREATE.js +5 -0
  154. package/src/client/websocket/handlers/THREAD_DELETE.js +5 -0
  155. package/src/client/websocket/handlers/THREAD_LIST_SYNC.js +5 -0
  156. package/src/client/websocket/handlers/THREAD_MEMBERS_UPDATE.js +5 -0
  157. package/src/client/websocket/handlers/THREAD_MEMBER_UPDATE.js +5 -0
  158. package/src/client/websocket/handlers/THREAD_UPDATE.js +16 -0
  159. package/src/client/websocket/handlers/TYPING_START.js +5 -0
  160. package/src/client/websocket/handlers/USER_GUILD_SETTINGS_UPDATE.js +6 -0
  161. package/src/client/websocket/handlers/USER_NOTE_UPDATE.js +5 -0
  162. package/src/client/websocket/handlers/USER_REQUIRED_ACTION_UPDATE.js +78 -0
  163. package/src/client/websocket/handlers/USER_SETTINGS_UPDATE.js +5 -0
  164. package/src/client/websocket/handlers/USER_UPDATE.js +5 -0
  165. package/src/client/websocket/handlers/VOICE_CHANNEL_EFFECT_SEND.js +16 -0
  166. package/src/client/websocket/handlers/VOICE_CHANNEL_STATUS_UPDATE.js +12 -0
  167. package/src/client/websocket/handlers/VOICE_SERVER_UPDATE.js +6 -0
  168. package/src/client/websocket/handlers/VOICE_STATE_UPDATE.js +5 -0
  169. package/src/client/websocket/handlers/WEBHOOKS_UPDATE.js +5 -0
  170. package/src/client/websocket/handlers/index.js +84 -0
  171. package/src/errors/DJSError.js +61 -0
  172. package/src/errors/Messages.js +217 -0
  173. package/src/errors/index.js +4 -0
  174. package/src/index.js +172 -0
  175. package/src/managers/ApplicationCommandManager.js +264 -0
  176. package/src/managers/ApplicationCommandPermissionsManager.js +417 -0
  177. package/src/managers/AutoModerationRuleManager.js +296 -0
  178. package/src/managers/BaseGuildEmojiManager.js +80 -0
  179. package/src/managers/BaseManager.js +19 -0
  180. package/src/managers/BillingManager.js +66 -0
  181. package/src/managers/CachedManager.js +71 -0
  182. package/src/managers/ChannelManager.js +148 -0
  183. package/src/managers/ClientUserSettingManager.js +372 -0
  184. package/src/managers/DataManager.js +61 -0
  185. package/src/managers/GuildBanManager.js +250 -0
  186. package/src/managers/GuildChannelManager.js +488 -0
  187. package/src/managers/GuildEmojiManager.js +171 -0
  188. package/src/managers/GuildEmojiRoleManager.js +118 -0
  189. package/src/managers/GuildForumThreadManager.js +108 -0
  190. package/src/managers/GuildInviteManager.js +213 -0
  191. package/src/managers/GuildManager.js +338 -0
  192. package/src/managers/GuildMemberManager.js +599 -0
  193. package/src/managers/GuildMemberRoleManager.js +195 -0
  194. package/src/managers/GuildScheduledEventManager.js +314 -0
  195. package/src/managers/GuildSettingManager.js +155 -0
  196. package/src/managers/GuildStickerManager.js +179 -0
  197. package/src/managers/GuildTextThreadManager.js +98 -0
  198. package/src/managers/InteractionManager.js +39 -0
  199. package/src/managers/MessageManager.js +423 -0
  200. package/src/managers/PermissionOverwriteManager.js +164 -0
  201. package/src/managers/PresenceManager.js +71 -0
  202. package/src/managers/ReactionManager.js +67 -0
  203. package/src/managers/ReactionUserManager.js +73 -0
  204. package/src/managers/RelationshipManager.js +278 -0
  205. package/src/managers/RoleManager.js +448 -0
  206. package/src/managers/SessionManager.js +66 -0
  207. package/src/managers/StageInstanceManager.js +162 -0
  208. package/src/managers/ThreadManager.js +175 -0
  209. package/src/managers/ThreadMemberManager.js +186 -0
  210. package/src/managers/UserManager.js +136 -0
  211. package/src/managers/UserNoteManager.js +53 -0
  212. package/src/managers/VoiceStateManager.js +59 -0
  213. package/src/rest/APIRequest.js +154 -0
  214. package/src/rest/APIRouter.js +53 -0
  215. package/src/rest/DiscordAPIError.js +119 -0
  216. package/src/rest/HTTPError.js +62 -0
  217. package/src/rest/RESTManager.js +67 -0
  218. package/src/rest/RateLimitError.js +55 -0
  219. package/src/rest/RequestHandler.js +466 -0
  220. package/src/sharding/Shard.js +444 -0
  221. package/src/sharding/ShardClientUtil.js +279 -0
  222. package/src/sharding/ShardingManager.js +319 -0
  223. package/src/structures/AnonymousGuild.js +98 -0
  224. package/src/structures/ApplicationCommand.js +593 -0
  225. package/src/structures/ApplicationRoleConnectionMetadata.js +48 -0
  226. package/src/structures/AutoModerationActionExecution.js +89 -0
  227. package/src/structures/AutoModerationRule.js +294 -0
  228. package/src/structures/AutocompleteInteraction.js +107 -0
  229. package/src/structures/Base.js +43 -0
  230. package/src/structures/BaseCommandInteraction.js +211 -0
  231. package/src/structures/BaseGuild.js +116 -0
  232. package/src/structures/BaseGuildEmoji.js +56 -0
  233. package/src/structures/BaseGuildTextChannel.js +191 -0
  234. package/src/structures/BaseGuildVoiceChannel.js +241 -0
  235. package/src/structures/BaseMessageComponent.js +181 -0
  236. package/src/structures/ButtonInteraction.js +11 -0
  237. package/src/structures/CallState.js +63 -0
  238. package/src/structures/CategoryChannel.js +85 -0
  239. package/src/structures/Channel.js +284 -0
  240. package/src/structures/ClientPresence.js +77 -0
  241. package/src/structures/ClientUser.js +449 -0
  242. package/src/structures/CommandInteraction.js +41 -0
  243. package/src/structures/CommandInteractionOptionResolver.js +276 -0
  244. package/src/structures/ContainerComponent.js +68 -0
  245. package/src/structures/ContextMenuInteraction.js +65 -0
  246. package/src/structures/DMChannel.js +219 -0
  247. package/src/structures/DirectoryChannel.js +20 -0
  248. package/src/structures/Emoji.js +148 -0
  249. package/src/structures/FileComponent.js +49 -0
  250. package/src/structures/ForumChannel.js +31 -0
  251. package/src/structures/GroupDMChannel.js +394 -0
  252. package/src/structures/Guild.js +1638 -0
  253. package/src/structures/GuildAuditLogs.js +746 -0
  254. package/src/structures/GuildBan.js +59 -0
  255. package/src/structures/GuildBoost.js +108 -0
  256. package/src/structures/GuildChannel.js +470 -0
  257. package/src/structures/GuildEmoji.js +161 -0
  258. package/src/structures/GuildMember.js +636 -0
  259. package/src/structures/GuildPreview.js +191 -0
  260. package/src/structures/GuildPreviewEmoji.js +27 -0
  261. package/src/structures/GuildScheduledEvent.js +536 -0
  262. package/src/structures/GuildTemplate.js +236 -0
  263. package/src/structures/Integration.js +188 -0
  264. package/src/structures/IntegrationApplication.js +96 -0
  265. package/src/structures/Interaction.js +290 -0
  266. package/src/structures/InteractionCollector.js +248 -0
  267. package/src/structures/InteractionWebhook.js +43 -0
  268. package/src/structures/Invite.js +358 -0
  269. package/src/structures/InviteGuild.js +23 -0
  270. package/src/structures/InviteStageInstance.js +86 -0
  271. package/src/structures/MediaChannel.js +11 -0
  272. package/src/structures/MediaGalleryComponent.js +41 -0
  273. package/src/structures/MediaGalleryItem.js +47 -0
  274. package/src/structures/Message.js +1252 -0
  275. package/src/structures/MessageActionRow.js +105 -0
  276. package/src/structures/MessageAttachment.js +216 -0
  277. package/src/structures/MessageButton.js +166 -0
  278. package/src/structures/MessageCollector.js +146 -0
  279. package/src/structures/MessageComponentInteraction.js +120 -0
  280. package/src/structures/MessageContextMenuInteraction.js +20 -0
  281. package/src/structures/MessageEmbed.js +596 -0
  282. package/src/structures/MessageMentions.js +273 -0
  283. package/src/structures/MessagePayload.js +354 -0
  284. package/src/structures/MessageReaction.js +181 -0
  285. package/src/structures/MessageSelectMenu.js +141 -0
  286. package/src/structures/Modal.js +161 -0
  287. package/src/structures/ModalSubmitFieldsResolver.js +53 -0
  288. package/src/structures/ModalSubmitInteraction.js +119 -0
  289. package/src/structures/NewsChannel.js +32 -0
  290. package/src/structures/OAuth2Guild.js +28 -0
  291. package/src/structures/PermissionOverwrites.js +198 -0
  292. package/src/structures/Poll.js +108 -0
  293. package/src/structures/PollAnswer.js +88 -0
  294. package/src/structures/Presence.js +1105 -0
  295. package/src/structures/ReactionCollector.js +229 -0
  296. package/src/structures/ReactionEmoji.js +31 -0
  297. package/src/structures/Role.js +590 -0
  298. package/src/structures/SectionComponent.js +48 -0
  299. package/src/structures/SelectMenuInteraction.js +21 -0
  300. package/src/structures/SeparatorComponent.js +48 -0
  301. package/src/structures/Session.js +81 -0
  302. package/src/structures/StageChannel.js +104 -0
  303. package/src/structures/StageInstance.js +208 -0
  304. package/src/structures/Sticker.js +310 -0
  305. package/src/structures/StickerPack.js +95 -0
  306. package/src/structures/StoreChannel.js +56 -0
  307. package/src/structures/Team.js +118 -0
  308. package/src/structures/TeamMember.js +80 -0
  309. package/src/structures/TextChannel.js +33 -0
  310. package/src/structures/TextDisplayComponent.js +40 -0
  311. package/src/structures/TextInputComponent.js +132 -0
  312. package/src/structures/ThreadChannel.js +605 -0
  313. package/src/structures/ThreadMember.js +105 -0
  314. package/src/structures/ThreadOnlyChannel.js +249 -0
  315. package/src/structures/ThumbnailComponent.js +57 -0
  316. package/src/structures/Typing.js +74 -0
  317. package/src/structures/UnfurledMediaItem.js +29 -0
  318. package/src/structures/User.js +622 -0
  319. package/src/structures/UserContextMenuInteraction.js +29 -0
  320. package/src/structures/VoiceChannel.js +110 -0
  321. package/src/structures/VoiceChannelEffect.js +69 -0
  322. package/src/structures/VoiceRegion.js +53 -0
  323. package/src/structures/VoiceState.js +354 -0
  324. package/src/structures/WebEmbed.js +373 -0
  325. package/src/structures/Webhook.js +478 -0
  326. package/src/structures/WelcomeChannel.js +60 -0
  327. package/src/structures/WelcomeScreen.js +48 -0
  328. package/src/structures/Widget.js +87 -0
  329. package/src/structures/WidgetMember.js +99 -0
  330. package/src/structures/interfaces/Application.js +825 -0
  331. package/src/structures/interfaces/Collector.js +300 -0
  332. package/src/structures/interfaces/InteractionResponses.js +313 -0
  333. package/src/structures/interfaces/TextBasedChannel.js +759 -0
  334. package/src/util/APITypes.js +59 -0
  335. package/src/util/ActivityFlags.js +44 -0
  336. package/src/util/ApplicationFlags.js +76 -0
  337. package/src/util/AttachmentFlags.js +38 -0
  338. package/src/util/BitField.js +170 -0
  339. package/src/util/ChannelFlags.js +45 -0
  340. package/src/util/Constants.js +1914 -0
  341. package/src/util/DataResolver.js +146 -0
  342. package/src/util/Formatters.js +228 -0
  343. package/src/util/GuildMemberFlags.js +43 -0
  344. package/src/util/Intents.js +74 -0
  345. package/src/util/InviteFlags.js +34 -0
  346. package/src/util/LimitedCollection.js +131 -0
  347. package/src/util/MessageFlags.js +63 -0
  348. package/src/util/Options.js +358 -0
  349. package/src/util/Permissions.js +202 -0
  350. package/src/util/PremiumUsageFlags.js +31 -0
  351. package/src/util/PurchasedFlags.js +33 -0
  352. package/src/util/RemoteAuth.js +382 -0
  353. package/src/util/RoleFlags.js +37 -0
  354. package/src/util/SnowflakeUtil.js +92 -0
  355. package/src/util/Speaking.js +33 -0
  356. package/src/util/Sweepers.js +466 -0
  357. package/src/util/SystemChannelFlags.js +55 -0
  358. package/src/util/ThreadMemberFlags.js +30 -0
  359. package/src/util/UserFlags.js +104 -0
  360. package/src/util/Util.js +1048 -0
  361. package/typings/enums.d.ts +439 -0
  362. package/typings/index.d.ts +8247 -0
  363. package/typings/index.test-d.ts +0 -0
  364. package/typings/rawDataTypes.d.ts +403 -0
@@ -0,0 +1,1638 @@
1
+ 'use strict';
2
+
3
+ const process = require('node:process');
4
+ const { Collection } = require('@discordjs/collection');
5
+ const AnonymousGuild = require('./AnonymousGuild');
6
+ const GuildAuditLogs = require('./GuildAuditLogs');
7
+ const GuildPreview = require('./GuildPreview');
8
+ const GuildTemplate = require('./GuildTemplate');
9
+ const Integration = require('./Integration');
10
+ const Webhook = require('./Webhook');
11
+ const WelcomeScreen = require('./WelcomeScreen');
12
+ const { Error } = require('../errors');
13
+ const AutoModerationRuleManager = require('../managers/AutoModerationRuleManager');
14
+ const GuildBanManager = require('../managers/GuildBanManager');
15
+ const GuildChannelManager = require('../managers/GuildChannelManager');
16
+ const GuildEmojiManager = require('../managers/GuildEmojiManager');
17
+ const GuildInviteManager = require('../managers/GuildInviteManager');
18
+ const GuildMemberManager = require('../managers/GuildMemberManager');
19
+ const GuildScheduledEventManager = require('../managers/GuildScheduledEventManager');
20
+ const GuildSettingManager = require('../managers/GuildSettingManager');
21
+ const GuildStickerManager = require('../managers/GuildStickerManager');
22
+ const PresenceManager = require('../managers/PresenceManager');
23
+ const RoleManager = require('../managers/RoleManager');
24
+ const StageInstanceManager = require('../managers/StageInstanceManager');
25
+ const VoiceStateManager = require('../managers/VoiceStateManager');
26
+ const {
27
+ ChannelTypes,
28
+ DefaultMessageNotificationLevels,
29
+ VerificationLevels,
30
+ ExplicitContentFilterLevels,
31
+ Status,
32
+ MFALevels,
33
+ PremiumTiers,
34
+ } = require('../util/Constants');
35
+ const DataResolver = require('../util/DataResolver');
36
+ const SystemChannelFlags = require('../util/SystemChannelFlags');
37
+ const Util = require('../util/Util');
38
+
39
+ let deprecationEmittedForSetChannelPositions = false;
40
+ let deprecationEmittedForSetRolePositions = false;
41
+ let deprecationEmittedForDeleted = false;
42
+ let deprecationEmittedForMe = false;
43
+
44
+ /**
45
+ * @type {WeakSet<Guild>}
46
+ * @private
47
+ * @internal
48
+ */
49
+ const deletedGuilds = new WeakSet();
50
+
51
+ /**
52
+ * Represents a guild (or a server) on Discord.
53
+ * <info>It's recommended to see if a guild is available before performing operations or reading data from it. You can
54
+ * check this with {@link Guild#available}.</info>
55
+ * @extends {AnonymousGuild}
56
+ */
57
+ class Guild extends AnonymousGuild {
58
+ constructor(client, data) {
59
+ super(client, data, false);
60
+
61
+ /**
62
+ * A manager of the members belonging to this guild
63
+ * @type {GuildMemberManager}
64
+ */
65
+ this.members = new GuildMemberManager(this);
66
+
67
+ /**
68
+ * A manager of the channels belonging to this guild
69
+ * @type {GuildChannelManager}
70
+ */
71
+ this.channels = new GuildChannelManager(this);
72
+
73
+ /**
74
+ * A manager of the bans belonging to this guild
75
+ * @type {GuildBanManager}
76
+ */
77
+ this.bans = new GuildBanManager(this);
78
+
79
+ /**
80
+ * A manager of the roles belonging to this guild
81
+ * @type {RoleManager}
82
+ */
83
+ this.roles = new RoleManager(this);
84
+
85
+ /**
86
+ * A manager of the presences belonging to this guild
87
+ * @type {PresenceManager}
88
+ */
89
+ this.presences = new PresenceManager(this.client);
90
+
91
+ /**
92
+ * A manager of the voice states of this guild
93
+ * @type {VoiceStateManager}
94
+ */
95
+ this.voiceStates = new VoiceStateManager(this);
96
+
97
+ /**
98
+ * A manager of the stage instances of this guild
99
+ * @type {StageInstanceManager}
100
+ */
101
+ this.stageInstances = new StageInstanceManager(this);
102
+
103
+ /**
104
+ * A manager of the invites of this guild
105
+ * @type {GuildInviteManager}
106
+ */
107
+ this.invites = new GuildInviteManager(this);
108
+
109
+ /**
110
+ * A manager of the scheduled events of this guild
111
+ * @type {GuildScheduledEventManager}
112
+ */
113
+ this.scheduledEvents = new GuildScheduledEventManager(this);
114
+
115
+ /**
116
+ * A manager of the auto moderation rules of this guild.
117
+ * @type {AutoModerationRuleManager}
118
+ */
119
+ this.autoModerationRules = new AutoModerationRuleManager(this);
120
+
121
+ /**
122
+ * All of the settings {@link Object}
123
+ * @type {GuildSettingManager}
124
+ */
125
+ this.settings = new GuildSettingManager(this);
126
+
127
+ if (!data) return;
128
+ if (data.unavailable) {
129
+ /**
130
+ * Whether the guild is available to access. If it is not available, it indicates a server outage
131
+ * @type {boolean}
132
+ */
133
+ this.available = false;
134
+ } else {
135
+ this._patch(data);
136
+ if (!data.channels) this.available = false;
137
+ }
138
+
139
+ /**
140
+ * The id of the shard this Guild belongs to.
141
+ * @type {number}
142
+ */
143
+ this.shardId = data.shardId;
144
+ }
145
+
146
+ /**
147
+ * Whether or not the structure has been deleted
148
+ * @type {boolean}
149
+ * @deprecated This will be removed in the next major version, see https://github.com/discordjs/discord.js/issues/7091
150
+ */
151
+ get deleted() {
152
+ if (!deprecationEmittedForDeleted) {
153
+ deprecationEmittedForDeleted = true;
154
+ process.emitWarning(
155
+ 'Guild#deleted is deprecated, see https://github.com/discordjs/discord.js/issues/7091.',
156
+ 'DeprecationWarning',
157
+ );
158
+ }
159
+
160
+ return deletedGuilds.has(this);
161
+ }
162
+
163
+ set deleted(value) {
164
+ if (!deprecationEmittedForDeleted) {
165
+ deprecationEmittedForDeleted = true;
166
+ process.emitWarning(
167
+ 'Guild#deleted is deprecated, see https://github.com/discordjs/discord.js/issues/7091.',
168
+ 'DeprecationWarning',
169
+ );
170
+ }
171
+
172
+ if (value) deletedGuilds.add(this);
173
+ else deletedGuilds.delete(this);
174
+ }
175
+
176
+ /**
177
+ * The Shard this Guild belongs to.
178
+ * @type {WebSocketShard}
179
+ * @readonly
180
+ */
181
+ get shard() {
182
+ return this.client.ws.shards.get(this.shardId);
183
+ }
184
+
185
+ _patch(data) {
186
+ super._patch(data);
187
+ this.id = data.id;
188
+ if ('name' in data) this.name = data.name;
189
+ if ('icon' in data) this.icon = data.icon;
190
+ if ('unavailable' in data) {
191
+ this.available = !data.unavailable;
192
+ } else {
193
+ this.available ??= true;
194
+ }
195
+
196
+ if ('discovery_splash' in data) {
197
+ /**
198
+ * The hash of the guild discovery splash image
199
+ * @type {?string}
200
+ */
201
+ this.discoverySplash = data.discovery_splash;
202
+ }
203
+
204
+ if ('member_count' in data) {
205
+ /**
206
+ * The full amount of members in this guild
207
+ * @type {number}
208
+ */
209
+ this.memberCount = data.member_count;
210
+ }
211
+
212
+ if ('large' in data) {
213
+ /**
214
+ * Whether the guild is "large" (has more than {@link WebsocketOptions large_threshold} members, 50 by default)
215
+ * @type {boolean}
216
+ */
217
+ this.large = Boolean(data.large);
218
+ }
219
+
220
+ if ('premium_progress_bar_enabled' in data) {
221
+ /**
222
+ * Whether this guild has its premium (boost) progress bar enabled
223
+ * @type {boolean}
224
+ */
225
+ this.premiumProgressBarEnabled = data.premium_progress_bar_enabled;
226
+ }
227
+
228
+ /**
229
+ * An array of enabled guild features, here are the possible values:
230
+ * * ANIMATED_ICON
231
+ * * AUTO_MODERATION
232
+ * * BANNER
233
+ * * COMMERCE
234
+ * * COMMUNITY
235
+ * * CREATOR_MONETIZABLE_PROVISIONAL
236
+ * * CREATOR_STORE_PAGE
237
+ * * DISCOVERABLE
238
+ * * FEATURABLE
239
+ * * INVITES_DISABLED
240
+ * * INVITE_SPLASH
241
+ * * MEMBER_VERIFICATION_GATE_ENABLED
242
+ * * NEWS
243
+ * * PARTNERED
244
+ * * PREVIEW_ENABLED
245
+ * * VANITY_URL
246
+ * * VERIFIED
247
+ * * VIP_REGIONS
248
+ * * WELCOME_SCREEN_ENABLED
249
+ * * TICKETED_EVENTS_ENABLED
250
+ * * MONETIZATION_ENABLED
251
+ * <warn>`MONETIZATION_ENABLED` has been replaced.
252
+ * See [this pull request](https://github.com/discord/discord-api-docs/pull/5724) for more information.</warn>
253
+ * * MORE_STICKERS
254
+ * * THREE_DAY_THREAD_ARCHIVE
255
+ * * SEVEN_DAY_THREAD_ARCHIVE
256
+ * * PRIVATE_THREADS
257
+ * * ROLE_ICONS
258
+ * * RAID_ALERTS_DISABLED
259
+ * * ROLE_SUBSCRIPTIONS_AVAILABLE_FOR_PURCHASE
260
+ * * ROLE_SUBSCRIPTIONS_ENABLED
261
+ * @typedef {string} Features
262
+ * @see {@link https://discord.com/developers/docs/resources/guild#guild-object-guild-features}
263
+ */
264
+
265
+ if ('application_id' in data) {
266
+ /**
267
+ * The id of the application that created this guild (if applicable)
268
+ * @type {?Snowflake}
269
+ */
270
+ this.applicationId = data.application_id;
271
+ }
272
+
273
+ if ('afk_timeout' in data) {
274
+ /**
275
+ * The time in seconds before a user is counted as "away from keyboard"
276
+ * @type {?number}
277
+ */
278
+ this.afkTimeout = data.afk_timeout;
279
+ }
280
+
281
+ if ('afk_channel_id' in data) {
282
+ /**
283
+ * The id of the voice channel where AFK members are moved
284
+ * @type {?Snowflake}
285
+ */
286
+ this.afkChannelId = data.afk_channel_id;
287
+ }
288
+
289
+ if ('system_channel_id' in data) {
290
+ /**
291
+ * The system channel's id
292
+ * @type {?Snowflake}
293
+ */
294
+ this.systemChannelId = data.system_channel_id;
295
+ }
296
+
297
+ if ('premium_tier' in data) {
298
+ /**
299
+ * The premium tier of this guild
300
+ * @type {PremiumTier}
301
+ */
302
+ this.premiumTier = PremiumTiers[data.premium_tier];
303
+ }
304
+
305
+ if ('widget_enabled' in data) {
306
+ /**
307
+ * Whether widget images are enabled on this guild
308
+ * @type {?boolean}
309
+ */
310
+ this.widgetEnabled = data.widget_enabled;
311
+ }
312
+
313
+ if ('widget_channel_id' in data) {
314
+ /**
315
+ * The widget channel's id, if enabled
316
+ * @type {?string}
317
+ */
318
+ this.widgetChannelId = data.widget_channel_id;
319
+ }
320
+
321
+ if ('explicit_content_filter' in data) {
322
+ /**
323
+ * The explicit content filter level of the guild
324
+ * @type {ExplicitContentFilterLevel}
325
+ */
326
+ this.explicitContentFilter = ExplicitContentFilterLevels[data.explicit_content_filter];
327
+ }
328
+
329
+ if ('mfa_level' in data) {
330
+ /**
331
+ * The required MFA level for this guild
332
+ * @type {MFALevel}
333
+ */
334
+ this.mfaLevel = MFALevels[data.mfa_level];
335
+ }
336
+
337
+ if ('joined_at' in data) {
338
+ /**
339
+ * The timestamp the client user joined the guild at
340
+ * @type {number}
341
+ */
342
+ this.joinedTimestamp = new Date(data.joined_at).getTime();
343
+ }
344
+
345
+ if ('default_message_notifications' in data) {
346
+ /**
347
+ * The default message notification level of the guild
348
+ * @type {DefaultMessageNotificationLevel}
349
+ */
350
+ this.defaultMessageNotifications = DefaultMessageNotificationLevels[data.default_message_notifications];
351
+ }
352
+
353
+ if ('system_channel_flags' in data) {
354
+ /**
355
+ * The value set for the guild's system channel flags
356
+ * @type {Readonly<SystemChannelFlags>}
357
+ */
358
+ this.systemChannelFlags = new SystemChannelFlags(data.system_channel_flags).freeze();
359
+ }
360
+
361
+ if ('max_members' in data) {
362
+ /**
363
+ * The maximum amount of members the guild can have
364
+ * @type {?number}
365
+ */
366
+ this.maximumMembers = data.max_members;
367
+ } else {
368
+ this.maximumMembers ??= null;
369
+ }
370
+
371
+ if ('max_presences' in data) {
372
+ /**
373
+ * The maximum amount of presences the guild can have
374
+ * <info>You will need to fetch the guild using {@link Guild#fetch} if you want to receive this parameter</info>
375
+ * @type {?number}
376
+ */
377
+ this.maximumPresences = data.max_presences ?? 25_000;
378
+ } else {
379
+ this.maximumPresences ??= null;
380
+ }
381
+
382
+ if ('max_video_channel_users' in data) {
383
+ /**
384
+ * The maximum amount of users allowed in a video channel.
385
+ * @type {?number}
386
+ */
387
+ this.maxVideoChannelUsers = data.max_video_channel_users;
388
+ } else {
389
+ this.maxVideoChannelUsers ??= null;
390
+ }
391
+
392
+ if ('max_stage_video_channel_users' in data) {
393
+ /**
394
+ * The maximum amount of users allowed in a stage video channel.
395
+ * @type {?number}
396
+ */
397
+ this.maxStageVideoChannelUsers = data.max_stage_video_channel_users;
398
+ } else {
399
+ this.maxStageVideoChannelUsers ??= null;
400
+ }
401
+
402
+ if ('approximate_member_count' in data) {
403
+ /**
404
+ * The approximate amount of members the guild has
405
+ * <info>You will need to fetch the guild using {@link Guild#fetch} if you want to receive this parameter</info>
406
+ * @type {?number}
407
+ */
408
+ this.approximateMemberCount = data.approximate_member_count;
409
+ } else {
410
+ this.approximateMemberCount ??= null;
411
+ }
412
+
413
+ if ('approximate_presence_count' in data) {
414
+ /**
415
+ * The approximate amount of presences the guild has
416
+ * <info>You will need to fetch the guild using {@link Guild#fetch} if you want to receive this parameter</info>
417
+ * @type {?number}
418
+ */
419
+ this.approximatePresenceCount = data.approximate_presence_count;
420
+ } else {
421
+ this.approximatePresenceCount ??= null;
422
+ }
423
+
424
+ /**
425
+ * The use count of the vanity URL code of the guild, if any
426
+ * <info>You will need to fetch this parameter using {@link Guild#fetchVanityData} if you want to receive it</info>
427
+ * @type {?number}
428
+ */
429
+ this.vanityURLUses ??= null;
430
+
431
+ if ('rules_channel_id' in data) {
432
+ /**
433
+ * The rules channel's id for the guild
434
+ * @type {?Snowflake}
435
+ */
436
+ this.rulesChannelId = data.rules_channel_id;
437
+ }
438
+
439
+ if ('public_updates_channel_id' in data) {
440
+ /**
441
+ * The community updates channel's id for the guild
442
+ * @type {?Snowflake}
443
+ */
444
+ this.publicUpdatesChannelId = data.public_updates_channel_id;
445
+ }
446
+
447
+ if ('preferred_locale' in data) {
448
+ /**
449
+ * The preferred locale of the guild, defaults to `en-US`
450
+ * @type {Locale}
451
+ * @see {@link https://discord.com/developers/docs/reference#locales}
452
+ */
453
+ this.preferredLocale = data.preferred_locale;
454
+ }
455
+
456
+ if ('safety_alerts_channel_id' in data) {
457
+ /**
458
+ * The safety alerts channel's id for the guild
459
+ * @type {?Snowflake}
460
+ */
461
+ this.safetyAlertsChannelId = data.safety_alerts_channel_id;
462
+ } else {
463
+ this.safetyAlertsChannelId ??= null;
464
+ }
465
+
466
+ if (data.channels) {
467
+ this.channels.cache.clear();
468
+ for (const rawChannel of data.channels) {
469
+ this.client.channels._add(rawChannel, this);
470
+ }
471
+ }
472
+
473
+ if (data.threads) {
474
+ for (const rawThread of data.threads) {
475
+ this.client.channels._add(rawThread, this);
476
+ }
477
+ }
478
+
479
+ if (data.roles) {
480
+ this.roles.cache.clear();
481
+ for (const role of data.roles) this.roles._add(role);
482
+ }
483
+
484
+ if (data.members) {
485
+ this.members.cache.clear();
486
+ for (const guildUser of data.members) this.members._add(guildUser);
487
+ }
488
+
489
+ if ('owner_id' in data) {
490
+ /**
491
+ * The user id of this guild's owner
492
+ * @type {Snowflake}
493
+ */
494
+ this.ownerId = data.owner_id;
495
+ }
496
+
497
+ if (data.presences) {
498
+ for (const presence of data.presences) {
499
+ this.presences._add(Object.assign(presence, { guild: this }));
500
+ }
501
+ }
502
+
503
+ if (data.stage_instances) {
504
+ this.stageInstances.cache.clear();
505
+ for (const stageInstance of data.stage_instances) {
506
+ this.stageInstances._add(stageInstance);
507
+ }
508
+ }
509
+
510
+ if (data.guild_scheduled_events) {
511
+ this.scheduledEvents.cache.clear();
512
+ for (const scheduledEvent of data.guild_scheduled_events) {
513
+ this.scheduledEvents._add(scheduledEvent);
514
+ }
515
+ }
516
+
517
+ if (data.voice_states) {
518
+ this.voiceStates.cache.clear();
519
+ for (const voiceState of data.voice_states) {
520
+ this.voiceStates._add(voiceState);
521
+ }
522
+ }
523
+
524
+ if (!this.emojis) {
525
+ /**
526
+ * A manager of the emojis belonging to this guild
527
+ * @type {GuildEmojiManager}
528
+ */
529
+ this.emojis = new GuildEmojiManager(this);
530
+ if (data.emojis) for (const emoji of data.emojis) this.emojis._add(emoji);
531
+ } else if (data.emojis) {
532
+ this.client.actions.GuildEmojisUpdate.handle({
533
+ guild_id: this.id,
534
+ emojis: data.emojis,
535
+ });
536
+ }
537
+
538
+ if (!this.stickers) {
539
+ /**
540
+ * A manager of the stickers belonging to this guild
541
+ * @type {GuildStickerManager}
542
+ */
543
+ this.stickers = new GuildStickerManager(this);
544
+ if (data.stickers) for (const sticker of data.stickers) this.stickers._add(sticker);
545
+ } else if (data.stickers) {
546
+ this.client.actions.GuildStickersUpdate.handle({
547
+ guild_id: this.id,
548
+ stickers: data.stickers,
549
+ });
550
+ }
551
+
552
+ if ('incidents_data' in data) {
553
+ /**
554
+ * Incident actions of a guild.
555
+ * @typedef {Object} IncidentActions
556
+ * @property {?Date} invitesDisabledUntil When invites would be enabled again
557
+ * @property {?Date} dmsDisabledUntil When direct messages would be enabled again
558
+ * @property {?Date} dmSpamDetectedAt When direct message spam was detected
559
+ * @property {?Date} raidDetectedAt When a raid was detected
560
+ */
561
+
562
+ /**
563
+ * The incidents data of this guild.
564
+ * <info>You will need to fetch the guild using {@link BaseGuild#fetch} if you want to receive
565
+ * this property.</info>
566
+ * @type {?IncidentActions}
567
+ */
568
+ this.incidentsData = data.incidents_data && Util.transformAPIIncidentsData(data.incidents_data);
569
+ } else {
570
+ this.incidentsData ??= null;
571
+ }
572
+ }
573
+
574
+ /**
575
+ * The time the client user joined the guild
576
+ * @type {Date}
577
+ * @readonly
578
+ */
579
+ get joinedAt() {
580
+ return new Date(this.joinedTimestamp);
581
+ }
582
+
583
+ /**
584
+ * The URL to this guild's discovery splash image.
585
+ * @param {StaticImageURLOptions} [options={}] Options for the Image URL
586
+ * @returns {?string}
587
+ */
588
+ discoverySplashURL({ format, size } = {}) {
589
+ return this.discoverySplash && this.client.rest.cdn.DiscoverySplash(this.id, this.discoverySplash, format, size);
590
+ }
591
+
592
+ /**
593
+ * Fetches the owner of the guild.
594
+ * If the member object isn't needed, use {@link Guild#ownerId} instead.
595
+ * @param {BaseFetchOptions} [options] The options for fetching the member
596
+ * @returns {Promise<GuildMember>}
597
+ */
598
+ fetchOwner(options) {
599
+ return this.members.fetch({ ...options, user: this.ownerId });
600
+ }
601
+
602
+ /**
603
+ * AFK voice channel for this guild
604
+ * @type {?VoiceChannel}
605
+ * @readonly
606
+ */
607
+ get afkChannel() {
608
+ return this.client.channels.resolve(this.afkChannelId);
609
+ }
610
+
611
+ /**
612
+ * System channel for this guild
613
+ * @type {?TextChannel}
614
+ * @readonly
615
+ */
616
+ get systemChannel() {
617
+ return this.client.channels.resolve(this.systemChannelId);
618
+ }
619
+
620
+ /**
621
+ * Safety alerts channel for this guild
622
+ * @type {?TextChannel}
623
+ * @readonly
624
+ */
625
+ get safetyAlertsChannel() {
626
+ return this.client.channels.resolve(this.safetyAlertsChannelId);
627
+ }
628
+
629
+ /**
630
+ * Widget channel for this guild
631
+ * @type {?(TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel|MediaChannel)}
632
+ * @readonly
633
+ */
634
+ get widgetChannel() {
635
+ return this.client.channels.resolve(this.widgetChannelId);
636
+ }
637
+
638
+ /**
639
+ * Rules channel for this guild
640
+ * @type {?TextChannel}
641
+ * @readonly
642
+ */
643
+ get rulesChannel() {
644
+ return this.client.channels.resolve(this.rulesChannelId);
645
+ }
646
+
647
+ /**
648
+ * Public updates channel for this guild
649
+ * @type {?TextChannel}
650
+ * @readonly
651
+ */
652
+ get publicUpdatesChannel() {
653
+ return this.client.channels.resolve(this.publicUpdatesChannelId);
654
+ }
655
+
656
+ /**
657
+ * The client user as a GuildMember of this guild
658
+ * @type {?GuildMember}
659
+ * @deprecated Use {@link GuildMemberManager#me} instead.
660
+ * @readonly
661
+ */
662
+ get me() {
663
+ if (!deprecationEmittedForMe) {
664
+ process.emitWarning('Guild#me is deprecated. Use Guild#members#me instead.', 'DeprecationWarning');
665
+ deprecationEmittedForMe = true;
666
+ }
667
+
668
+ return this.members.me;
669
+ }
670
+
671
+ /**
672
+ * The maximum bitrate available for this guild
673
+ * @type {number}
674
+ * @readonly
675
+ */
676
+ get maximumBitrate() {
677
+ if (this.features.includes('VIP_REGIONS')) {
678
+ return 384_000;
679
+ }
680
+
681
+ switch (PremiumTiers[this.premiumTier]) {
682
+ case PremiumTiers.TIER_1:
683
+ return 128_000;
684
+ case PremiumTiers.TIER_2:
685
+ return 256_000;
686
+ case PremiumTiers.TIER_3:
687
+ return 384_000;
688
+ default:
689
+ return 96_000;
690
+ }
691
+ }
692
+
693
+ /**
694
+ * Fetches a collection of integrations to this guild.
695
+ * Resolves with a collection mapping integrations by their ids.
696
+ * @returns {Promise<Collection<Snowflake|string, Integration>>}
697
+ * @example
698
+ * // Fetch integrations
699
+ * guild.fetchIntegrations()
700
+ * .then(integrations => console.log(`Fetched ${integrations.size} integrations`))
701
+ * .catch(console.error);
702
+ */
703
+ async fetchIntegrations() {
704
+ const data = await this.client.api.guilds(this.id).integrations.get();
705
+ return data.reduce(
706
+ (collection, integration) => collection.set(integration.id, new Integration(this.client, integration, this)),
707
+ new Collection(),
708
+ );
709
+ }
710
+
711
+ /**
712
+ * Fetches a collection of templates from this guild.
713
+ * Resolves with a collection mapping templates by their codes.
714
+ * @returns {Promise<Collection<string, GuildTemplate>>}
715
+ */
716
+ async fetchTemplates() {
717
+ const templates = await this.client.api.guilds(this.id).templates.get();
718
+ return templates.reduce((col, data) => col.set(data.code, new GuildTemplate(this.client, data)), new Collection());
719
+ }
720
+
721
+ /**
722
+ * Fetches the welcome screen for this guild.
723
+ * @returns {Promise<WelcomeScreen>}
724
+ */
725
+ async fetchWelcomeScreen() {
726
+ const data = await this.client.api.guilds(this.id, 'welcome-screen').get();
727
+ return new WelcomeScreen(this, data);
728
+ }
729
+
730
+ /**
731
+ * Creates a template for the guild.
732
+ * @param {string} name The name for the template
733
+ * @param {string} [description] The description for the template
734
+ * @returns {Promise<GuildTemplate>}
735
+ */
736
+ async createTemplate(name, description) {
737
+ const data = await this.client.api.guilds(this.id).templates.post({ data: { name, description } });
738
+ return new GuildTemplate(this.client, data);
739
+ }
740
+
741
+ /**
742
+ * Obtains a guild preview for this guild from Discord.
743
+ * @returns {Promise<GuildPreview>}
744
+ */
745
+ async fetchPreview() {
746
+ const data = await this.client.api.guilds(this.id).preview.get();
747
+ return new GuildPreview(this.client, data);
748
+ }
749
+
750
+ /**
751
+ * An object containing information about a guild's vanity invite.
752
+ * @typedef {Object} Vanity
753
+ * @property {?string} code Vanity invite code
754
+ * @property {number} uses How many times this invite has been used
755
+ */
756
+
757
+ /**
758
+ * Fetches the vanity URL invite object to this guild.
759
+ * Resolves with an object containing the vanity URL invite code and the use count
760
+ * @returns {Promise<Vanity>}
761
+ * @example
762
+ * // Fetch invite data
763
+ * guild.fetchVanityData()
764
+ * .then(res => {
765
+ * console.log(`Vanity URL: https://discord.gg/${res.code} with ${res.uses} uses`);
766
+ * })
767
+ * .catch(console.error);
768
+ */
769
+ async fetchVanityData() {
770
+ const data = await this.client.api.guilds(this.id, 'vanity-url').get();
771
+ this.vanityURLCode = data.code;
772
+ this.vanityURLUses = data.uses;
773
+
774
+ return data;
775
+ }
776
+
777
+ /**
778
+ * Fetches all webhooks for the guild.
779
+ * @returns {Promise<Collection<Snowflake, Webhook>>}
780
+ * @example
781
+ * // Fetch webhooks
782
+ * guild.fetchWebhooks()
783
+ * .then(webhooks => console.log(`Fetched ${webhooks.size} webhooks`))
784
+ * .catch(console.error);
785
+ */
786
+ async fetchWebhooks() {
787
+ const apiHooks = await this.client.api.guilds(this.id).webhooks.get();
788
+ const hooks = new Collection();
789
+ for (const hook of apiHooks) hooks.set(hook.id, new Webhook(this.client, hook));
790
+ return hooks;
791
+ }
792
+
793
+ /**
794
+ * Fetches the guild widget data, requires the widget to be enabled.
795
+ * @returns {Promise<Widget>}
796
+ * @example
797
+ * // Fetches the guild widget data
798
+ * guild.fetchWidget()
799
+ * .then(widget => console.log(`The widget shows ${widget.channels.size} channels`))
800
+ * .catch(console.error);
801
+ */
802
+ fetchWidget() {
803
+ return this.client.fetchGuildWidget(this.id);
804
+ }
805
+
806
+ /**
807
+ * Data for the Guild Widget Settings object
808
+ * @typedef {Object} GuildWidgetSettings
809
+ * @property {boolean} enabled Whether the widget is enabled
810
+ * @property {?GuildChannel} channel The widget invite channel
811
+ */
812
+
813
+ /**
814
+ * The Guild Widget Settings object
815
+ * @typedef {Object} GuildWidgetSettingsData
816
+ * @property {boolean} enabled Whether the widget is enabled
817
+ * @property {?GuildChannelResolvable} channel The widget invite channel
818
+ */
819
+
820
+ /**
821
+ * Fetches the guild widget settings.
822
+ * @returns {Promise<GuildWidgetSettings>}
823
+ * @example
824
+ * // Fetches the guild widget settings
825
+ * guild.fetchWidgetSettings()
826
+ * .then(widget => console.log(`The widget is ${widget.enabled ? 'enabled' : 'disabled'}`))
827
+ * .catch(console.error);
828
+ */
829
+ async fetchWidgetSettings() {
830
+ const data = await this.client.api.guilds(this.id).widget.get();
831
+ this.widgetEnabled = data.enabled;
832
+ this.widgetChannelId = data.channel_id;
833
+ return {
834
+ enabled: data.enabled,
835
+ channel: data.channel_id ? this.channels.cache.get(data.channel_id) : null,
836
+ };
837
+ }
838
+
839
+ /**
840
+ * Options used to fetch audit logs.
841
+ * @typedef {Object} GuildAuditLogsFetchOptions
842
+ * @property {Snowflake|GuildAuditLogsEntry} [before] Consider only entries before this entry
843
+ * @property {Snowflake|GuildAuditLogsEntry} [after] Consider only entries after this entry
844
+ * @property {number} [limit] The number of entries to return
845
+ * @property {UserResolvable} [user] Only return entries for actions made by this user
846
+ * @property {AuditLogAction|number} [type] Only return entries for this action type
847
+ */
848
+
849
+ /**
850
+ * Fetches audit logs for this guild.
851
+ * @param {GuildAuditLogsFetchOptions} [options={}] Options for fetching audit logs
852
+ * @returns {Promise<GuildAuditLogs>}
853
+ * @example
854
+ * // Output audit log entries
855
+ * guild.fetchAuditLogs()
856
+ * .then(audit => console.log(audit.entries.first()))
857
+ * .catch(console.error);
858
+ */
859
+ async fetchAuditLogs({ before, after, limit, user, type } = {}) {
860
+ const data = await this.client.api.guilds(this.id)['audit-logs'].get({
861
+ query: {
862
+ before: before?.id ?? before,
863
+ after: after?.id ?? after,
864
+ limit,
865
+ user_id: this.client.users.resolveId(user),
866
+ action_type: typeof type === 'string' ? GuildAuditLogs.Actions[type] : type,
867
+ },
868
+ });
869
+
870
+ return GuildAuditLogs.build(this, data);
871
+ }
872
+
873
+ /**
874
+ * The data for editing a guild.
875
+ * @typedef {Object} GuildEditData
876
+ * @property {string} [name] The name of the guild
877
+ * @property {?(VerificationLevel|number)} [verificationLevel] The verification level of the guild
878
+ * @property {?(ExplicitContentFilterLevel|number)} [explicitContentFilter] The level of the explicit content filter
879
+ * @property {?VoiceChannelResolvable} [afkChannel] The AFK channel of the guild
880
+ * @property {?TextChannelResolvable} [systemChannel] The system channel of the guild
881
+ * @property {number} [afkTimeout] The AFK timeout of the guild
882
+ * @property {?(BufferResolvable|Base64Resolvable)} [icon] The icon of the guild
883
+ * @property {GuildMemberResolvable} [owner] The owner of the guild
884
+ * @property {?(BufferResolvable|Base64Resolvable)} [splash] The invite splash image of the guild
885
+ * @property {?(BufferResolvable|Base64Resolvable)} [discoverySplash] The discovery splash image of the guild
886
+ * @property {?(BufferResolvable|Base64Resolvable)} [banner] The banner of the guild
887
+ * @property {?(DefaultMessageNotificationLevel|number)} [defaultMessageNotifications] The default message
888
+ * notification level of the guild
889
+ * @property {SystemChannelFlagsResolvable} [systemChannelFlags] The system channel flags of the guild
890
+ * @property {?TextChannelResolvable} [rulesChannel] The rules channel of the guild
891
+ * @property {?TextChannelResolvable} [publicUpdatesChannel] The community updates channel of the guild
892
+ * @property {?string} [preferredLocale] The preferred locale of the guild
893
+ * @property {?TextChannelResolvable} [safetyAlertsChannel] The safety alerts channel of the guild
894
+ * @property {boolean} [premiumProgressBarEnabled] Whether the guild's premium progress bar is enabled
895
+ * @property {?string} [description] The discovery description of the guild
896
+ * @property {Features[]} [features] The features of the guild
897
+ */
898
+
899
+ /**
900
+ * Data that can be resolved to a Text Channel object. This can be:
901
+ * * A TextChannel
902
+ * * A Snowflake
903
+ * @typedef {TextChannel|Snowflake} TextChannelResolvable
904
+ */
905
+
906
+ /**
907
+ * Data that can be resolved to a Voice Channel object. This can be:
908
+ * * A VoiceChannel
909
+ * * A Snowflake
910
+ * @typedef {VoiceChannel|Snowflake} VoiceChannelResolvable
911
+ */
912
+
913
+ /**
914
+ * Updates the guild with new information - e.g. a new name.
915
+ * @param {GuildEditData} data The data to update the guild with
916
+ * @param {string} [reason] Reason for editing this guild
917
+ * @returns {Promise<Guild>}
918
+ * @example
919
+ * // Set the guild name
920
+ * guild.edit({
921
+ * name: 'Discord Guild',
922
+ * })
923
+ * .then(updated => console.log(`New guild name ${updated}`))
924
+ * .catch(console.error);
925
+ */
926
+ async edit(data, reason) {
927
+ const _data = {};
928
+ if (data.name) _data.name = data.name;
929
+ if (typeof data.verificationLevel !== 'undefined') {
930
+ _data.verification_level =
931
+ typeof data.verificationLevel === 'number'
932
+ ? data.verificationLevel
933
+ : VerificationLevels[data.verificationLevel];
934
+ }
935
+ if (typeof data.afkChannel !== 'undefined') {
936
+ _data.afk_channel_id = this.client.channels.resolveId(data.afkChannel);
937
+ }
938
+ if (typeof data.systemChannel !== 'undefined') {
939
+ _data.system_channel_id = this.client.channels.resolveId(data.systemChannel);
940
+ }
941
+ if (data.afkTimeout) _data.afk_timeout = Number(data.afkTimeout);
942
+ if (typeof data.icon !== 'undefined') _data.icon = await DataResolver.resolveImage(data.icon);
943
+ if (data.owner) _data.owner_id = this.client.users.resolveId(data.owner);
944
+ if (typeof data.splash !== 'undefined') _data.splash = await DataResolver.resolveImage(data.splash);
945
+ if (typeof data.discoverySplash !== 'undefined') {
946
+ _data.discovery_splash = await DataResolver.resolveImage(data.discoverySplash);
947
+ }
948
+ if (typeof data.banner !== 'undefined') _data.banner = await DataResolver.resolveImage(data.banner);
949
+ if (typeof data.explicitContentFilter !== 'undefined') {
950
+ _data.explicit_content_filter =
951
+ typeof data.explicitContentFilter === 'number'
952
+ ? data.explicitContentFilter
953
+ : ExplicitContentFilterLevels[data.explicitContentFilter];
954
+ }
955
+ if (typeof data.defaultMessageNotifications !== 'undefined') {
956
+ _data.default_message_notifications =
957
+ typeof data.defaultMessageNotifications === 'number'
958
+ ? data.defaultMessageNotifications
959
+ : DefaultMessageNotificationLevels[data.defaultMessageNotifications];
960
+ }
961
+ if (typeof data.systemChannelFlags !== 'undefined') {
962
+ _data.system_channel_flags = SystemChannelFlags.resolve(data.systemChannelFlags);
963
+ }
964
+ if (typeof data.rulesChannel !== 'undefined') {
965
+ _data.rules_channel_id = this.client.channels.resolveId(data.rulesChannel);
966
+ }
967
+ if (typeof data.publicUpdatesChannel !== 'undefined') {
968
+ _data.public_updates_channel_id = this.client.channels.resolveId(data.publicUpdatesChannel);
969
+ }
970
+ if (typeof data.features !== 'undefined') {
971
+ _data.features = data.features;
972
+ }
973
+ if (typeof data.description !== 'undefined') {
974
+ _data.description = data.description;
975
+ }
976
+ if (typeof data.preferredLocale !== 'undefined') _data.preferred_locale = data.preferredLocale;
977
+ if (typeof data.safetyAlertsChannel !== 'undefined') {
978
+ _data.safety_alerts_channel_id = this.client.channels.resolveId(data.safetyAlertsChannel);
979
+ }
980
+ if ('premiumProgressBarEnabled' in data) _data.premium_progress_bar_enabled = data.premiumProgressBarEnabled;
981
+ const newData = await this.client.api.guilds(this.id).patch({ data: _data, reason });
982
+ return this.client.actions.GuildUpdate.handle(newData).updated;
983
+ }
984
+
985
+ /**
986
+ * Welcome channel data
987
+ * @typedef {Object} WelcomeChannelData
988
+ * @property {string} description The description to show for this welcome channel
989
+ * @property {TextChannel|NewsChannel|StoreChannel|Snowflake} channel The channel to link for this welcome channel
990
+ * @property {EmojiIdentifierResolvable} [emoji] The emoji to display for this welcome channel
991
+ */
992
+
993
+ /**
994
+ * Welcome screen edit data
995
+ * @typedef {Object} WelcomeScreenEditData
996
+ * @property {boolean} [enabled] Whether the welcome screen is enabled
997
+ * @property {string} [description] The description for the welcome screen
998
+ * @property {WelcomeChannelData[]} [welcomeChannels] The welcome channel data for the welcome screen
999
+ */
1000
+
1001
+ /**
1002
+ * Data that can be resolved to a GuildTextChannel object. This can be:
1003
+ * * A TextChannel
1004
+ * * A NewsChannel
1005
+ * * A Snowflake
1006
+ * @typedef {TextChannel|NewsChannel|Snowflake} GuildTextChannelResolvable
1007
+ */
1008
+
1009
+ /**
1010
+ * Data that can be resolved to a GuildVoiceChannel object. This can be:
1011
+ * * A VoiceChannel
1012
+ * * A StageChannel
1013
+ * * A Snowflake
1014
+ * @typedef {VoiceChannel|StageChannel|Snowflake} GuildVoiceChannelResolvable
1015
+ */
1016
+
1017
+ /**
1018
+ * Updates the guild's welcome screen
1019
+ * @param {WelcomeScreenEditData} data Data to edit the welcome screen with
1020
+ * @returns {Promise<WelcomeScreen>}
1021
+ * @example
1022
+ * guild.editWelcomeScreen({
1023
+ * description: 'Hello World',
1024
+ * enabled: true,
1025
+ * welcomeChannels: [
1026
+ * {
1027
+ * description: 'foobar',
1028
+ * channel: '222197033908436994',
1029
+ * }
1030
+ * ],
1031
+ * })
1032
+ */
1033
+ async editWelcomeScreen(data) {
1034
+ const { enabled, description, welcomeChannels } = data;
1035
+ const welcome_channels = welcomeChannels?.map(welcomeChannelData => {
1036
+ const emoji = this.emojis.resolve(welcomeChannelData.emoji);
1037
+ return {
1038
+ emoji_id: emoji?.id,
1039
+ emoji_name: emoji?.name ?? welcomeChannelData.emoji,
1040
+ channel_id: this.channels.resolveId(welcomeChannelData.channel),
1041
+ description: welcomeChannelData.description,
1042
+ };
1043
+ });
1044
+
1045
+ const patchData = await this.client.api.guilds(this.id, 'welcome-screen').patch({
1046
+ data: {
1047
+ welcome_channels,
1048
+ description,
1049
+ enabled,
1050
+ },
1051
+ });
1052
+ return new WelcomeScreen(this, patchData);
1053
+ }
1054
+
1055
+ /**
1056
+ * Edits the level of the explicit content filter.
1057
+ * @param {?(ExplicitContentFilterLevel|number)} explicitContentFilter The new level of the explicit content filter
1058
+ * @param {string} [reason] Reason for changing the level of the guild's explicit content filter
1059
+ * @returns {Promise<Guild>}
1060
+ */
1061
+ setExplicitContentFilter(explicitContentFilter, reason) {
1062
+ return this.edit({ explicitContentFilter }, reason);
1063
+ }
1064
+
1065
+ /* eslint-disable max-len */
1066
+ /**
1067
+ * Edits the setting of the default message notifications of the guild.
1068
+ * @param {?(DefaultMessageNotificationLevel|number)} defaultMessageNotifications The new default message notification level of the guild
1069
+ * @param {string} [reason] Reason for changing the setting of the default message notifications
1070
+ * @returns {Promise<Guild>}
1071
+ */
1072
+ setDefaultMessageNotifications(defaultMessageNotifications, reason) {
1073
+ return this.edit({ defaultMessageNotifications }, reason);
1074
+ }
1075
+ /* eslint-enable max-len */
1076
+
1077
+ /**
1078
+ * Edits the flags of the default message notifications of the guild.
1079
+ * @param {SystemChannelFlagsResolvable} systemChannelFlags The new flags for the default message notifications
1080
+ * @param {string} [reason] Reason for changing the flags of the default message notifications
1081
+ * @returns {Promise<Guild>}
1082
+ */
1083
+ setSystemChannelFlags(systemChannelFlags, reason) {
1084
+ return this.edit({ systemChannelFlags }, reason);
1085
+ }
1086
+
1087
+ /**
1088
+ * Edits the name of the guild.
1089
+ * @param {string} name The new name of the guild
1090
+ * @param {string} [reason] Reason for changing the guild's name
1091
+ * @returns {Promise<Guild>}
1092
+ * @example
1093
+ * // Edit the guild name
1094
+ * guild.setName('Discord Guild')
1095
+ * .then(updated => console.log(`Updated guild name to ${updated.name}`))
1096
+ * .catch(console.error);
1097
+ */
1098
+ setName(name, reason) {
1099
+ return this.edit({ name }, reason);
1100
+ }
1101
+
1102
+ /**
1103
+ * Edits the verification level of the guild.
1104
+ * @param {?(VerificationLevel|number)} verificationLevel The new verification level of the guild
1105
+ * @param {string} [reason] Reason for changing the guild's verification level
1106
+ * @returns {Promise<Guild>}
1107
+ * @example
1108
+ * // Edit the guild verification level
1109
+ * guild.setVerificationLevel(1)
1110
+ * .then(updated => console.log(`Updated guild verification level to ${guild.verificationLevel}`))
1111
+ * .catch(console.error);
1112
+ */
1113
+ setVerificationLevel(verificationLevel, reason) {
1114
+ return this.edit({ verificationLevel }, reason);
1115
+ }
1116
+
1117
+ /**
1118
+ * Edits the AFK channel of the guild.
1119
+ * @param {?VoiceChannelResolvable} afkChannel The new AFK channel
1120
+ * @param {string} [reason] Reason for changing the guild's AFK channel
1121
+ * @returns {Promise<Guild>}
1122
+ * @example
1123
+ * // Edit the guild AFK channel
1124
+ * guild.setAFKChannel(channel)
1125
+ * .then(updated => console.log(`Updated guild AFK channel to ${guild.afkChannel.name}`))
1126
+ * .catch(console.error);
1127
+ */
1128
+ setAFKChannel(afkChannel, reason) {
1129
+ return this.edit({ afkChannel }, reason);
1130
+ }
1131
+
1132
+ /**
1133
+ * Edits the system channel of the guild.
1134
+ * @param {?TextChannelResolvable} systemChannel The new system channel
1135
+ * @param {string} [reason] Reason for changing the guild's system channel
1136
+ * @returns {Promise<Guild>}
1137
+ * @example
1138
+ * // Edit the guild system channel
1139
+ * guild.setSystemChannel(channel)
1140
+ * .then(updated => console.log(`Updated guild system channel to ${guild.systemChannel.name}`))
1141
+ * .catch(console.error);
1142
+ */
1143
+ setSystemChannel(systemChannel, reason) {
1144
+ return this.edit({ systemChannel }, reason);
1145
+ }
1146
+
1147
+ /**
1148
+ * Edits the AFK timeout of the guild.
1149
+ * @param {number} afkTimeout The time in seconds that a user must be idle to be considered AFK
1150
+ * @param {string} [reason] Reason for changing the guild's AFK timeout
1151
+ * @returns {Promise<Guild>}
1152
+ * @example
1153
+ * // Edit the guild AFK channel
1154
+ * guild.setAFKTimeout(60)
1155
+ * .then(updated => console.log(`Updated guild AFK timeout to ${guild.afkTimeout}`))
1156
+ * .catch(console.error);
1157
+ */
1158
+ setAFKTimeout(afkTimeout, reason) {
1159
+ return this.edit({ afkTimeout }, reason);
1160
+ }
1161
+
1162
+ /**
1163
+ * Sets a new guild icon.
1164
+ * @param {?(Base64Resolvable|BufferResolvable)} icon The new icon of the guild
1165
+ * @param {string} [reason] Reason for changing the guild's icon
1166
+ * @returns {Promise<Guild>}
1167
+ * @example
1168
+ * // Edit the guild icon
1169
+ * guild.setIcon('./icon.png')
1170
+ * .then(updated => console.log('Updated the guild icon'))
1171
+ * .catch(console.error);
1172
+ */
1173
+ setIcon(icon, reason) {
1174
+ return this.edit({ icon }, reason);
1175
+ }
1176
+
1177
+ /**
1178
+ * Sets a new owner of the guild.
1179
+ * @param {GuildMemberResolvable} owner The new owner of the guild
1180
+ * @param {string} [reason] Reason for setting the new owner
1181
+ * @returns {Promise<Guild>}
1182
+ * @example
1183
+ * // Edit the guild owner
1184
+ * guild.setOwner(guild.members.cache.first())
1185
+ * .then(guild => guild.fetchOwner())
1186
+ * .then(owner => console.log(`Updated the guild owner to ${owner.displayName}`))
1187
+ * .catch(console.error);
1188
+ */
1189
+ setOwner(owner, reason) {
1190
+ return this.edit({ owner }, reason);
1191
+ }
1192
+
1193
+ /**
1194
+ * Sets a new guild invite splash image.
1195
+ * @param {?(Base64Resolvable|BufferResolvable)} splash The new invite splash image of the guild
1196
+ * @param {string} [reason] Reason for changing the guild's invite splash image
1197
+ * @returns {Promise<Guild>}
1198
+ * @example
1199
+ * // Edit the guild splash
1200
+ * guild.setSplash('./splash.png')
1201
+ * .then(updated => console.log('Updated the guild splash'))
1202
+ * .catch(console.error);
1203
+ */
1204
+ setSplash(splash, reason) {
1205
+ return this.edit({ splash }, reason);
1206
+ }
1207
+
1208
+ /**
1209
+ * Sets a new guild discovery splash image.
1210
+ * @param {?(Base64Resolvable|BufferResolvable)} discoverySplash The new discovery splash image of the guild
1211
+ * @param {string} [reason] Reason for changing the guild's discovery splash image
1212
+ * @returns {Promise<Guild>}
1213
+ * @example
1214
+ * // Edit the guild discovery splash
1215
+ * guild.setDiscoverySplash('./discoverysplash.png')
1216
+ * .then(updated => console.log('Updated the guild discovery splash'))
1217
+ * .catch(console.error);
1218
+ */
1219
+ setDiscoverySplash(discoverySplash, reason) {
1220
+ return this.edit({ discoverySplash }, reason);
1221
+ }
1222
+
1223
+ /**
1224
+ * Sets a new guild banner.
1225
+ * @param {?(Base64Resolvable|BufferResolvable)} banner The new banner of the guild
1226
+ * @param {string} [reason] Reason for changing the guild's banner
1227
+ * @returns {Promise<Guild>}
1228
+ * @example
1229
+ * guild.setBanner('./banner.png')
1230
+ * .then(updated => console.log('Updated the guild banner'))
1231
+ * .catch(console.error);
1232
+ */
1233
+ setBanner(banner, reason) {
1234
+ return this.edit({ banner }, reason);
1235
+ }
1236
+
1237
+ /**
1238
+ * Edits the rules channel of the guild.
1239
+ * @param {?TextChannelResolvable} rulesChannel The new rules channel
1240
+ * @param {string} [reason] Reason for changing the guild's rules channel
1241
+ * @returns {Promise<Guild>}
1242
+ * @example
1243
+ * // Edit the guild rules channel
1244
+ * guild.setRulesChannel(channel)
1245
+ * .then(updated => console.log(`Updated guild rules channel to ${guild.rulesChannel.name}`))
1246
+ * .catch(console.error);
1247
+ */
1248
+ setRulesChannel(rulesChannel, reason) {
1249
+ return this.edit({ rulesChannel }, reason);
1250
+ }
1251
+
1252
+ /**
1253
+ * Edits the community updates channel of the guild.
1254
+ * @param {?TextChannelResolvable} publicUpdatesChannel The new community updates channel
1255
+ * @param {string} [reason] Reason for changing the guild's community updates channel
1256
+ * @returns {Promise<Guild>}
1257
+ * @example
1258
+ * // Edit the guild community updates channel
1259
+ * guild.setPublicUpdatesChannel(channel)
1260
+ * .then(updated => console.log(`Updated guild community updates channel to ${guild.publicUpdatesChannel.name}`))
1261
+ * .catch(console.error);
1262
+ */
1263
+ setPublicUpdatesChannel(publicUpdatesChannel, reason) {
1264
+ return this.edit({ publicUpdatesChannel }, reason);
1265
+ }
1266
+
1267
+ /**
1268
+ * Edits the preferred locale of the guild.
1269
+ * @param {?string} preferredLocale The new preferred locale of the guild
1270
+ * @param {string} [reason] Reason for changing the guild's preferred locale
1271
+ * @returns {Promise<Guild>}
1272
+ * @example
1273
+ * // Edit the guild preferred locale
1274
+ * guild.setPreferredLocale('en-US')
1275
+ * .then(updated => console.log(`Updated guild preferred locale to ${guild.preferredLocale}`))
1276
+ * .catch(console.error);
1277
+ */
1278
+ setPreferredLocale(preferredLocale, reason) {
1279
+ return this.edit({ preferredLocale }, reason);
1280
+ }
1281
+
1282
+ /**
1283
+ * Edits the safety alerts channel of the guild.
1284
+ * @param {?TextChannelResolvable} safetyAlertsChannel The new safety alerts channel
1285
+ * @param {string} [reason] Reason for changing the guild's safety alerts channel
1286
+ * @returns {Promise<Guild>}
1287
+ * @example
1288
+ * // Edit the guild safety alerts channel
1289
+ * guild.setSafetyAlertsChannel(channel)
1290
+ * .then(updated => console.log(`Updated guild safety alerts channel to ${updated.safetyAlertsChannel.name}`))
1291
+ * .catch(console.error);
1292
+ */
1293
+ setSafetyAlertsChannel(safetyAlertsChannel, reason) {
1294
+ return this.edit({ safetyAlertsChannel }, reason);
1295
+ }
1296
+
1297
+ /**
1298
+ * Edits the enabled state of the guild's premium progress bar
1299
+ * @param {boolean} [enabled=true] The new enabled state of the guild's premium progress bar
1300
+ * @param {string} [reason] Reason for changing the state of the guild's premium progress bar
1301
+ * @returns {Promise<Guild>}
1302
+ */
1303
+ setPremiumProgressBarEnabled(enabled = true, reason) {
1304
+ return this.edit({ premiumProgressBarEnabled: enabled }, reason);
1305
+ }
1306
+
1307
+ /**
1308
+ * Data that can be resolved to give a Category Channel object. This can be:
1309
+ * * A CategoryChannel object
1310
+ * * A Snowflake
1311
+ * @typedef {CategoryChannel|Snowflake} CategoryChannelResolvable
1312
+ */
1313
+
1314
+ /**
1315
+ * The data needed for updating a channel's position.
1316
+ * @typedef {Object} ChannelPosition
1317
+ * @property {GuildChannel|Snowflake} channel Channel to update
1318
+ * @property {number} [position] New position for the channel
1319
+ * @property {CategoryChannelResolvable} [parent] Parent channel for this channel
1320
+ * @property {boolean} [lockPermissions] If the overwrites should be locked to the parents overwrites
1321
+ */
1322
+
1323
+ /**
1324
+ * Batch-updates the guild's channels' positions.
1325
+ * <info>Only one channel's parent can be changed at a time</info>
1326
+ * @param {ChannelPosition[]} channelPositions Channel positions to update
1327
+ * @returns {Promise<Guild>}
1328
+ * @deprecated Use {@link GuildChannelManager#setPositions} instead
1329
+ * @example
1330
+ * guild.setChannelPositions([{ channel: channelId, position: newChannelIndex }])
1331
+ * .then(guild => console.log(`Updated channel positions for ${guild}`))
1332
+ * .catch(console.error);
1333
+ */
1334
+ setChannelPositions(channelPositions) {
1335
+ if (!deprecationEmittedForSetChannelPositions) {
1336
+ process.emitWarning(
1337
+ 'The Guild#setChannelPositions method is deprecated. Use GuildChannelManager#setPositions instead.',
1338
+ 'DeprecationWarning',
1339
+ );
1340
+
1341
+ deprecationEmittedForSetChannelPositions = true;
1342
+ }
1343
+
1344
+ return this.channels.setPositions(channelPositions);
1345
+ }
1346
+
1347
+ /**
1348
+ * The data needed for updating a guild role's position
1349
+ * @typedef {Object} GuildRolePosition
1350
+ * @property {RoleResolvable} role The role's id
1351
+ * @property {number} position The position to update
1352
+ */
1353
+
1354
+ /**
1355
+ * Batch-updates the guild's role positions
1356
+ * @param {GuildRolePosition[]} rolePositions Role positions to update
1357
+ * @returns {Promise<Guild>}
1358
+ * @deprecated Use {@link RoleManager#setPositions} instead
1359
+ * @example
1360
+ * guild.setRolePositions([{ role: roleId, position: updatedRoleIndex }])
1361
+ * .then(guild => console.log(`Role positions updated for ${guild}`))
1362
+ * .catch(console.error);
1363
+ */
1364
+ setRolePositions(rolePositions) {
1365
+ if (!deprecationEmittedForSetRolePositions) {
1366
+ process.emitWarning(
1367
+ 'The Guild#setRolePositions method is deprecated. Use RoleManager#setPositions instead.',
1368
+ 'DeprecationWarning',
1369
+ );
1370
+
1371
+ deprecationEmittedForSetRolePositions = true;
1372
+ }
1373
+
1374
+ return this.roles.setPositions(rolePositions);
1375
+ }
1376
+
1377
+ /**
1378
+ * Edits the guild's widget settings.
1379
+ * @param {GuildWidgetSettingsData} settings The widget settings for the guild
1380
+ * @param {string} [reason] Reason for changing the guild's widget settings
1381
+ * @returns {Promise<Guild>}
1382
+ */
1383
+ async setWidgetSettings(settings, reason) {
1384
+ await this.client.api.guilds(this.id).widget.patch({
1385
+ data: {
1386
+ enabled: settings.enabled,
1387
+ channel_id: this.channels.resolveId(settings.channel),
1388
+ },
1389
+ reason,
1390
+ });
1391
+ return this;
1392
+ }
1393
+
1394
+ /**
1395
+ * Sets whether this guild's invites are disabled.
1396
+ * @param {boolean} [disabled=true] Whether the invites are disabled
1397
+ * @returns {Promise<Guild>}
1398
+ */
1399
+ disableInvites(disabled = true) {
1400
+ const features = this.features.filter(feature => feature !== 'INVITES_DISABLED');
1401
+ if (disabled) features.push('INVITES_DISABLED');
1402
+ return this.edit({ features });
1403
+ }
1404
+
1405
+ /**
1406
+ * Sets the incident actions for a guild.
1407
+ * @param {IncidentActionsEditOptions} incidentActions The incident actions to set
1408
+ * @returns {Promise<IncidentActions>}
1409
+ */
1410
+ setIncidentActions(incidentActions) {
1411
+ return this.client.guilds.setIncidentActions(this.id, incidentActions);
1412
+ }
1413
+
1414
+ /**
1415
+ * Leaves the guild.
1416
+ * @returns {Promise<Guild>}
1417
+ * @example
1418
+ * // Leave a guild
1419
+ * guild.leave()
1420
+ * .then(guild => console.log(`Left the guild: ${guild.name}`))
1421
+ * .catch(console.error);
1422
+ */
1423
+ async leave() {
1424
+ if (this.ownerId === this.client.user.id) throw new Error('GUILD_OWNED');
1425
+ await this.client.api.users('@me').guilds(this.id).delete();
1426
+ return this.client.actions.GuildDelete.handle({ id: this.id }).guild;
1427
+ }
1428
+
1429
+ /**
1430
+ * Deletes the guild.
1431
+ * @returns {Promise<Guild>}
1432
+ * @example
1433
+ * // Delete a guild
1434
+ * guild.delete()
1435
+ * .then(g => console.log(`Deleted the guild ${g}`))
1436
+ * .catch(console.error);
1437
+ */
1438
+ async delete() {
1439
+ await this.client.api.guilds(this.id).delete();
1440
+ return this.client.actions.GuildDelete.handle({ id: this.id }).guild;
1441
+ }
1442
+
1443
+ /**
1444
+ * Whether this guild equals another guild. It compares all properties, so for most operations
1445
+ * it is advisable to just compare `guild.id === guild2.id` as it is much faster and is often
1446
+ * what most users need.
1447
+ * @param {Guild} guild The guild to compare with
1448
+ * @returns {boolean}
1449
+ */
1450
+ equals(guild) {
1451
+ return (
1452
+ guild &&
1453
+ guild instanceof this.constructor &&
1454
+ this.id === guild.id &&
1455
+ this.available === guild.available &&
1456
+ this.splash === guild.splash &&
1457
+ this.discoverySplash === guild.discoverySplash &&
1458
+ this.name === guild.name &&
1459
+ this.memberCount === guild.memberCount &&
1460
+ this.large === guild.large &&
1461
+ this.icon === guild.icon &&
1462
+ this.ownerId === guild.ownerId &&
1463
+ this.verificationLevel === guild.verificationLevel &&
1464
+ (this.features === guild.features ||
1465
+ (this.features.length === guild.features.length &&
1466
+ this.features.every((feat, i) => feat === guild.features[i])))
1467
+ );
1468
+ }
1469
+
1470
+ toJSON() {
1471
+ const json = super.toJSON({
1472
+ available: false,
1473
+ createdTimestamp: true,
1474
+ nameAcronym: true,
1475
+ presences: false,
1476
+ voiceStates: false,
1477
+ });
1478
+ json.iconURL = this.iconURL();
1479
+ json.splashURL = this.splashURL();
1480
+ json.discoverySplashURL = this.discoverySplashURL();
1481
+ json.bannerURL = this.bannerURL();
1482
+ return json;
1483
+ }
1484
+
1485
+ /**
1486
+ * Marks the guild as read.
1487
+ * @returns {Promise<void>}
1488
+ * @example
1489
+ * const guild = client.guilds.cache.get('id');
1490
+ * guild.markAsRead();
1491
+ */
1492
+ markAsRead() {
1493
+ return this.client.api.guilds(this.id).ack.post();
1494
+ }
1495
+
1496
+ /**
1497
+ * Set Community Feature.
1498
+ * @param {boolean} stats True / False to enable / disable Community Feature
1499
+ * @param {GuildTextChannelResolvable} [publicUpdatesChannel] The community updates channel of the guild
1500
+ * @param {GuildTextChannelResolvable} [rulesChannel] The new rules channel
1501
+ * @param {string} [reason] Reason for changing the community feature
1502
+ * @returns {Promise<Guild>}
1503
+ */
1504
+ async setCommunity(stats = true, publicUpdatesChannel, rulesChannel, reason) {
1505
+ if (stats) {
1506
+ // Check everyone role
1507
+ const everyoneRole = this.roles.everyone;
1508
+ if (everyoneRole.mentionable) {
1509
+ await everyoneRole.setMentionable(false, reason);
1510
+ }
1511
+ // Setting
1512
+ return this.edit(
1513
+ {
1514
+ defaultMessageNotifications: 'ONLY_MENTIONS',
1515
+ explicitContentFilter: 'ALL_MEMBERS',
1516
+ features: [...this.features, 'COMMUNITY'],
1517
+ publicUpdatesChannel: this.channels.resolveId(publicUpdatesChannel) || '1',
1518
+ rulesChannel: this.channels.resolveId(rulesChannel) || '1',
1519
+ verificationLevel: VerificationLevels[this.verificationLevel] < 1 ? 'LOW' : this.verificationLevel, // Email
1520
+ },
1521
+ reason,
1522
+ );
1523
+ } else {
1524
+ return this.edit(
1525
+ {
1526
+ publicUpdatesChannel: null,
1527
+ rulesChannel: null,
1528
+ features: this.features.filter(f => f !== 'COMMUNITY'),
1529
+ preferredLocale: this.preferredLocale,
1530
+ description: this.description,
1531
+ },
1532
+ reason,
1533
+ );
1534
+ }
1535
+ }
1536
+
1537
+ /**
1538
+ * Get the top emojis of this guild.
1539
+ * @returns {Promise<Collection<number, GuildEmoji>>}
1540
+ */
1541
+ topEmojis() {
1542
+ return new Promise((resolve, reject) => {
1543
+ this.client.api
1544
+ .guilds(this.id)
1545
+ ['top-emojis'].get()
1546
+ .then(data => {
1547
+ const emojis = new Collection();
1548
+ for (const emoji of data.items) {
1549
+ emojis.set(emoji.emoji_rank, this.emojis.cache.get(emoji.emoji_id));
1550
+ }
1551
+ resolve(emojis);
1552
+ })
1553
+ .catch(reject);
1554
+ });
1555
+ }
1556
+
1557
+ /**
1558
+ * Set the vanity URL to this guild.
1559
+ * Resolves with an object containing the vanity URL invite code and the use count.
1560
+ * @param {string} [code=''] Vanity URL code
1561
+ * @returns {Promise<Vanity>}
1562
+ * @example
1563
+ * // Set invite code
1564
+ * guild.setVanityCode('elysia', '123456')
1565
+ * .then(res => {
1566
+ * console.log(`Vanity URL: https://discord.gg/${res.code} with ${res.uses} uses`);
1567
+ * })
1568
+ * .catch(console.error);
1569
+ */
1570
+ async setVanityCode(code = '') {
1571
+ if (typeof code !== 'string') throw new TypeError('INVALID_VANITY_URL_CODE');
1572
+ const data = await this.client.api.guilds(this.id, 'vanity-url').patch({
1573
+ data: { code },
1574
+ });
1575
+ this.vanityURLCode = data.code;
1576
+ this.vanityURLUses = data.uses;
1577
+
1578
+ return data;
1579
+ }
1580
+
1581
+ /**
1582
+ * The voice state adapter for this guild that can be used with @discordjs/voice to play audio in voice
1583
+ * and stage channels.
1584
+ * @type {Function}
1585
+ * @readonly
1586
+ */
1587
+ get voiceAdapterCreator() {
1588
+ return methods => {
1589
+ this.client.voice.adapters.set(this.id, methods);
1590
+ return {
1591
+ sendPayload: data => {
1592
+ if (this.shard.status !== Status.READY) return false;
1593
+ this.shard.send(data);
1594
+ return true;
1595
+ },
1596
+ destroy: () => {
1597
+ this.client.voice.adapters.delete(this.id);
1598
+ },
1599
+ };
1600
+ };
1601
+ }
1602
+
1603
+ /**
1604
+ * Creates a collection of this guild's roles, sorted by their position and ids.
1605
+ * @returns {Collection<Snowflake, Role>}
1606
+ * @private
1607
+ */
1608
+ _sortedRoles() {
1609
+ return Util.discordSort(this.roles.cache);
1610
+ }
1611
+
1612
+ /**
1613
+ * Creates a collection of this guild's or a specific category's channels, sorted by their position and ids.
1614
+ * @param {GuildChannel} [channel] Category to get the channels of
1615
+ * @returns {Collection<Snowflake, GuildChannel>}
1616
+ * @private
1617
+ */
1618
+ _sortedChannels(channel) {
1619
+ const category = channel.type === ChannelTypes.GUILD_CATEGORY;
1620
+ return Util.discordSort(
1621
+ this.channels.cache.filter(
1622
+ c =>
1623
+ (['GUILD_TEXT', 'GUILD_NEWS', 'GUILD_STORE'].includes(channel.type)
1624
+ ? ['GUILD_TEXT', 'GUILD_NEWS', 'GUILD_STORE'].includes(c.type)
1625
+ : c.type === channel.type) &&
1626
+ (category || c.parent === channel.parent),
1627
+ ),
1628
+ );
1629
+ }
1630
+ }
1631
+
1632
+ exports.Guild = Guild;
1633
+ exports.deletedGuilds = deletedGuilds;
1634
+
1635
+ /**
1636
+ * @external APIGuild
1637
+ * @see {@link https://discord.com/developers/docs/resources/guild#guild-object}
1638
+ */