djs-selfbot-v13 3.2.2 → 3.7.1

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