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