lolka.js 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (337) hide show
  1. package/LICENSE +191 -0
  2. package/README.md +148 -0
  3. package/package.json +104 -0
  4. package/src/client/Client.js +943 -0
  5. package/src/client/actions/Action.js +151 -0
  6. package/src/client/actions/ActionsManager.js +75 -0
  7. package/src/client/actions/ChannelCreate.js +25 -0
  8. package/src/client/actions/ChannelDelete.js +24 -0
  9. package/src/client/actions/ChannelUpdate.js +42 -0
  10. package/src/client/actions/GuildChannelsPositionUpdate.js +21 -0
  11. package/src/client/actions/GuildEmojiCreate.js +21 -0
  12. package/src/client/actions/GuildEmojiDelete.js +20 -0
  13. package/src/client/actions/GuildEmojiUpdate.js +21 -0
  14. package/src/client/actions/GuildEmojisUpdate.js +34 -0
  15. package/src/client/actions/GuildMemberRemove.js +33 -0
  16. package/src/client/actions/GuildMemberUpdate.js +45 -0
  17. package/src/client/actions/GuildRoleCreate.js +27 -0
  18. package/src/client/actions/GuildRoleDelete.js +30 -0
  19. package/src/client/actions/GuildRolesPositionUpdate.js +21 -0
  20. package/src/client/actions/GuildScheduledEventDelete.js +32 -0
  21. package/src/client/actions/GuildScheduledEventUserAdd.js +33 -0
  22. package/src/client/actions/GuildScheduledEventUserRemove.js +33 -0
  23. package/src/client/actions/GuildSoundboardSoundDelete.js +30 -0
  24. package/src/client/actions/GuildStickerCreate.js +21 -0
  25. package/src/client/actions/GuildStickerDelete.js +20 -0
  26. package/src/client/actions/GuildStickerUpdate.js +21 -0
  27. package/src/client/actions/GuildStickersUpdate.js +34 -0
  28. package/src/client/actions/GuildUpdate.js +34 -0
  29. package/src/client/actions/InteractionCreate.js +110 -0
  30. package/src/client/actions/MessageCreate.js +43 -0
  31. package/src/client/actions/MessageDelete.js +33 -0
  32. package/src/client/actions/MessageDeleteBulk.js +49 -0
  33. package/src/client/actions/MessagePollVoteAdd.js +41 -0
  34. package/src/client/actions/MessagePollVoteRemove.js +39 -0
  35. package/src/client/actions/MessageReactionAdd.js +72 -0
  36. package/src/client/actions/MessageReactionRemove.js +51 -0
  37. package/src/client/actions/MessageReactionRemoveAll.js +34 -0
  38. package/src/client/actions/MessageReactionRemoveEmoji.js +29 -0
  39. package/src/client/actions/MessageUpdate.js +26 -0
  40. package/src/client/actions/StageInstanceCreate.js +29 -0
  41. package/src/client/actions/StageInstanceDelete.js +32 -0
  42. package/src/client/actions/StageInstanceUpdate.js +31 -0
  43. package/src/client/actions/ThreadCreate.js +26 -0
  44. package/src/client/actions/ThreadMembersUpdate.js +49 -0
  45. package/src/client/actions/TypingStart.js +30 -0
  46. package/src/client/actions/UserUpdate.js +37 -0
  47. package/src/client/voice/ClientVoiceManager.js +48 -0
  48. package/src/client/websocket/handlers/APPLICATION_COMMAND_PERMISSIONS_UPDATE.js +30 -0
  49. package/src/client/websocket/handlers/AUTO_MODERATION_ACTION_EXECUTION.js +18 -0
  50. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_CREATE.js +19 -0
  51. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_DELETE.js +22 -0
  52. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_UPDATE.js +21 -0
  53. package/src/client/websocket/handlers/CHANNEL_CREATE.js +5 -0
  54. package/src/client/websocket/handlers/CHANNEL_DELETE.js +5 -0
  55. package/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.js +23 -0
  56. package/src/client/websocket/handlers/CHANNEL_UPDATE.js +17 -0
  57. package/src/client/websocket/handlers/ENTITLEMENT_CREATE.js +15 -0
  58. package/src/client/websocket/handlers/ENTITLEMENT_DELETE.js +19 -0
  59. package/src/client/websocket/handlers/ENTITLEMENT_UPDATE.js +17 -0
  60. package/src/client/websocket/handlers/GUILD_AUDIT_LOG_ENTRY_CREATE.js +20 -0
  61. package/src/client/websocket/handlers/GUILD_BAN_ADD.js +16 -0
  62. package/src/client/websocket/handlers/GUILD_BAN_REMOVE.js +21 -0
  63. package/src/client/websocket/handlers/GUILD_CREATE.js +35 -0
  64. package/src/client/websocket/handlers/GUILD_DELETE.js +37 -0
  65. package/src/client/websocket/handlers/GUILD_EMOJIS_UPDATE.js +5 -0
  66. package/src/client/websocket/handlers/GUILD_INTEGRATIONS_UPDATE.js +16 -0
  67. package/src/client/websocket/handlers/GUILD_MEMBERS_CHUNK.js +41 -0
  68. package/src/client/websocket/handlers/GUILD_MEMBER_ADD.js +18 -0
  69. package/src/client/websocket/handlers/GUILD_MEMBER_REMOVE.js +5 -0
  70. package/src/client/websocket/handlers/GUILD_MEMBER_UPDATE.js +5 -0
  71. package/src/client/websocket/handlers/GUILD_ROLE_CREATE.js +5 -0
  72. package/src/client/websocket/handlers/GUILD_ROLE_DELETE.js +5 -0
  73. package/src/client/websocket/handlers/GUILD_ROLE_UPDATE.js +22 -0
  74. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_CREATE.js +18 -0
  75. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_DELETE.js +5 -0
  76. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_UPDATE.js +20 -0
  77. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_ADD.js +5 -0
  78. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_REMOVE.js +5 -0
  79. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUNDS_UPDATE.js +25 -0
  80. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_CREATE.js +19 -0
  81. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_DELETE.js +5 -0
  82. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_UPDATE.js +21 -0
  83. package/src/client/websocket/handlers/GUILD_STICKERS_UPDATE.js +5 -0
  84. package/src/client/websocket/handlers/GUILD_UPDATE.js +5 -0
  85. package/src/client/websocket/handlers/INTERACTION_CREATE.js +5 -0
  86. package/src/client/websocket/handlers/INVITE_CREATE.js +21 -0
  87. package/src/client/websocket/handlers/INVITE_DELETE.js +24 -0
  88. package/src/client/websocket/handlers/MESSAGE_CREATE.js +5 -0
  89. package/src/client/websocket/handlers/MESSAGE_DELETE.js +5 -0
  90. package/src/client/websocket/handlers/MESSAGE_DELETE_BULK.js +5 -0
  91. package/src/client/websocket/handlers/MESSAGE_POLL_VOTE_ADD.js +5 -0
  92. package/src/client/websocket/handlers/MESSAGE_POLL_VOTE_REMOVE.js +5 -0
  93. package/src/client/websocket/handlers/MESSAGE_REACTION_ADD.js +5 -0
  94. package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE.js +5 -0
  95. package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_ALL.js +5 -0
  96. package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_EMOJI.js +5 -0
  97. package/src/client/websocket/handlers/MESSAGE_UPDATE.js +17 -0
  98. package/src/client/websocket/handlers/PRESENCE_UPDATE.js +43 -0
  99. package/src/client/websocket/handlers/RATE_LIMITED.js +24 -0
  100. package/src/client/websocket/handlers/READY.js +30 -0
  101. package/src/client/websocket/handlers/SOUNDBOARD_SOUNDS.js +25 -0
  102. package/src/client/websocket/handlers/STAGE_INSTANCE_CREATE.js +5 -0
  103. package/src/client/websocket/handlers/STAGE_INSTANCE_DELETE.js +5 -0
  104. package/src/client/websocket/handlers/STAGE_INSTANCE_UPDATE.js +5 -0
  105. package/src/client/websocket/handlers/SUBSCRIPTION_CREATE.js +15 -0
  106. package/src/client/websocket/handlers/SUBSCRIPTION_DELETE.js +17 -0
  107. package/src/client/websocket/handlers/SUBSCRIPTION_UPDATE.js +17 -0
  108. package/src/client/websocket/handlers/THREAD_CREATE.js +5 -0
  109. package/src/client/websocket/handlers/THREAD_DELETE.js +18 -0
  110. package/src/client/websocket/handlers/THREAD_LIST_SYNC.js +52 -0
  111. package/src/client/websocket/handlers/THREAD_MEMBERS_UPDATE.js +5 -0
  112. package/src/client/websocket/handlers/THREAD_MEMBER_UPDATE.js +26 -0
  113. package/src/client/websocket/handlers/THREAD_UPDATE.js +17 -0
  114. package/src/client/websocket/handlers/TYPING_START.js +5 -0
  115. package/src/client/websocket/handlers/USER_UPDATE.js +5 -0
  116. package/src/client/websocket/handlers/VOICE_CHANNEL_EFFECT_SEND.js +17 -0
  117. package/src/client/websocket/handlers/VOICE_SERVER_UPDATE.js +33 -0
  118. package/src/client/websocket/handlers/VOICE_STATE_UPDATE.js +38 -0
  119. package/src/client/websocket/handlers/WEBHOOKS_UPDATE.js +17 -0
  120. package/src/client/websocket/handlers/index.js +78 -0
  121. package/src/errors/DJSError.js +52 -0
  122. package/src/errors/ErrorCodes.js +280 -0
  123. package/src/errors/Messages.js +159 -0
  124. package/src/errors/index.js +7 -0
  125. package/src/index.js +261 -0
  126. package/src/managers/ApplicationCommandManager.js +305 -0
  127. package/src/managers/ApplicationCommandPermissionsManager.js +452 -0
  128. package/src/managers/ApplicationEmojiManager.js +152 -0
  129. package/src/managers/AutoModerationRuleManager.js +310 -0
  130. package/src/managers/BaseManager.js +21 -0
  131. package/src/managers/CachedManager.js +68 -0
  132. package/src/managers/CategoryChannelChildManager.js +85 -0
  133. package/src/managers/ChannelManager.js +197 -0
  134. package/src/managers/DMMessageManager.js +19 -0
  135. package/src/managers/DataManager.js +66 -0
  136. package/src/managers/EntitlementManager.js +185 -0
  137. package/src/managers/GuildApplicationCommandManager.js +31 -0
  138. package/src/managers/GuildBanManager.js +224 -0
  139. package/src/managers/GuildChannelManager.js +556 -0
  140. package/src/managers/GuildEmojiManager.js +264 -0
  141. package/src/managers/GuildEmojiRoleManager.js +136 -0
  142. package/src/managers/GuildForumThreadManager.js +88 -0
  143. package/src/managers/GuildInviteManager.js +239 -0
  144. package/src/managers/GuildManager.js +268 -0
  145. package/src/managers/GuildMemberManager.js +622 -0
  146. package/src/managers/GuildMemberRoleManager.js +232 -0
  147. package/src/managers/GuildMessageManager.js +35 -0
  148. package/src/managers/GuildScheduledEventManager.js +333 -0
  149. package/src/managers/GuildSoundboardSoundManager.js +226 -0
  150. package/src/managers/GuildStickerManager.js +195 -0
  151. package/src/managers/GuildTextThreadManager.js +95 -0
  152. package/src/managers/MessageManager.js +355 -0
  153. package/src/managers/PartialGroupDMMessageManager.js +19 -0
  154. package/src/managers/PermissionOverwriteManager.js +177 -0
  155. package/src/managers/PollAnswerVoterManager.js +62 -0
  156. package/src/managers/PresenceManager.js +63 -0
  157. package/src/managers/ReactionManager.js +75 -0
  158. package/src/managers/ReactionUserManager.js +85 -0
  159. package/src/managers/RoleManager.js +446 -0
  160. package/src/managers/StageInstanceManager.js +169 -0
  161. package/src/managers/SubscriptionManager.js +86 -0
  162. package/src/managers/ThreadManager.js +213 -0
  163. package/src/managers/ThreadMemberManager.js +197 -0
  164. package/src/managers/UserManager.js +149 -0
  165. package/src/managers/VoiceStateManager.js +64 -0
  166. package/src/sharding/Shard.js +506 -0
  167. package/src/sharding/ShardClientUtil.js +292 -0
  168. package/src/sharding/ShardingManager.js +390 -0
  169. package/src/structures/ActionRow.js +34 -0
  170. package/src/structures/ActivityInstance.js +52 -0
  171. package/src/structures/ActivityLocation.js +65 -0
  172. package/src/structures/AnnouncementChannel.js +29 -0
  173. package/src/structures/AnonymousGuild.js +107 -0
  174. package/src/structures/ApplicationCommand.js +657 -0
  175. package/src/structures/ApplicationEmoji.js +186 -0
  176. package/src/structures/ApplicationRoleConnectionMetadata.js +52 -0
  177. package/src/structures/Attachment.js +181 -0
  178. package/src/structures/AuthorizingIntegrationOwners.js +64 -0
  179. package/src/structures/AutoModerationActionExecution.js +131 -0
  180. package/src/structures/AutoModerationRule.js +317 -0
  181. package/src/structures/AutocompleteInteraction.js +112 -0
  182. package/src/structures/Base.js +45 -0
  183. package/src/structures/BaseChannel.js +188 -0
  184. package/src/structures/BaseGuild.js +134 -0
  185. package/src/structures/BaseGuildEmoji.js +111 -0
  186. package/src/structures/BaseGuildTextChannel.js +225 -0
  187. package/src/structures/BaseGuildVoiceChannel.js +265 -0
  188. package/src/structures/BaseInteraction.js +378 -0
  189. package/src/structures/BaseInvite.js +187 -0
  190. package/src/structures/BaseSelectMenuComponent.js +62 -0
  191. package/src/structures/ButtonComponent.js +72 -0
  192. package/src/structures/ButtonInteraction.js +12 -0
  193. package/src/structures/CategoryChannel.js +50 -0
  194. package/src/structures/ChannelSelectMenuComponent.js +22 -0
  195. package/src/structures/ChannelSelectMenuInteraction.js +36 -0
  196. package/src/structures/ChatInputCommandInteraction.js +45 -0
  197. package/src/structures/ClientApplication.js +463 -0
  198. package/src/structures/ClientPresence.js +89 -0
  199. package/src/structures/ClientUser.js +221 -0
  200. package/src/structures/CommandInteraction.js +188 -0
  201. package/src/structures/CommandInteractionOptionResolver.js +336 -0
  202. package/src/structures/Component.js +62 -0
  203. package/src/structures/ContainerComponent.js +66 -0
  204. package/src/structures/ContextMenuCommandInteraction.js +69 -0
  205. package/src/structures/DMChannel.js +162 -0
  206. package/src/structures/DirectoryChannel.js +40 -0
  207. package/src/structures/Embed.js +254 -0
  208. package/src/structures/Emoji.js +115 -0
  209. package/src/structures/Entitlement.js +199 -0
  210. package/src/structures/FileComponent.js +44 -0
  211. package/src/structures/ForumChannel.js +34 -0
  212. package/src/structures/GroupDMInvite.js +37 -0
  213. package/src/structures/Guild.js +1557 -0
  214. package/src/structures/GuildAuditLogs.js +97 -0
  215. package/src/structures/GuildAuditLogsEntry.js +552 -0
  216. package/src/structures/GuildBan.js +65 -0
  217. package/src/structures/GuildChannel.js +511 -0
  218. package/src/structures/GuildEmoji.js +160 -0
  219. package/src/structures/GuildInvite.js +223 -0
  220. package/src/structures/GuildMember.js +650 -0
  221. package/src/structures/GuildOnboarding.js +71 -0
  222. package/src/structures/GuildOnboardingPrompt.js +88 -0
  223. package/src/structures/GuildOnboardingPromptOption.js +96 -0
  224. package/src/structures/GuildPreview.js +213 -0
  225. package/src/structures/GuildPreviewEmoji.js +30 -0
  226. package/src/structures/GuildScheduledEvent.js +579 -0
  227. package/src/structures/GuildTemplate.js +221 -0
  228. package/src/structures/Integration.js +243 -0
  229. package/src/structures/IntegrationApplication.js +82 -0
  230. package/src/structures/InteractionCallback.js +83 -0
  231. package/src/structures/InteractionCallbackResource.js +57 -0
  232. package/src/structures/InteractionCallbackResponse.js +36 -0
  233. package/src/structures/InteractionCollector.js +256 -0
  234. package/src/structures/InteractionWebhook.js +67 -0
  235. package/src/structures/InviteGuild.js +24 -0
  236. package/src/structures/LabelComponent.js +54 -0
  237. package/src/structures/MediaChannel.js +12 -0
  238. package/src/structures/MediaGalleryComponent.js +34 -0
  239. package/src/structures/MediaGalleryItem.js +56 -0
  240. package/src/structures/MentionableSelectMenuComponent.js +12 -0
  241. package/src/structures/MentionableSelectMenuInteraction.js +76 -0
  242. package/src/structures/Message.js +1203 -0
  243. package/src/structures/MessageCollector.js +157 -0
  244. package/src/structures/MessageComponentInteraction.js +128 -0
  245. package/src/structures/MessageContextMenuCommandInteraction.js +22 -0
  246. package/src/structures/MessageMentions.js +323 -0
  247. package/src/structures/MessagePayload.js +346 -0
  248. package/src/structures/MessageReaction.js +214 -0
  249. package/src/structures/ModalComponentResolver.js +269 -0
  250. package/src/structures/ModalSubmitInteraction.js +274 -0
  251. package/src/structures/OAuth2Guild.js +31 -0
  252. package/src/structures/PartialGroupDMChannel.js +146 -0
  253. package/src/structures/PermissionOverwrites.js +221 -0
  254. package/src/structures/Poll.js +190 -0
  255. package/src/structures/PollAnswer.js +98 -0
  256. package/src/structures/Presence.js +429 -0
  257. package/src/structures/PrimaryEntryPointCommandInteraction.js +12 -0
  258. package/src/structures/ReactionCollector.js +246 -0
  259. package/src/structures/ReactionEmoji.js +33 -0
  260. package/src/structures/Role.js +539 -0
  261. package/src/structures/RoleSelectMenuComponent.js +12 -0
  262. package/src/structures/RoleSelectMenuInteraction.js +36 -0
  263. package/src/structures/SKU.js +59 -0
  264. package/src/structures/SectionComponent.js +46 -0
  265. package/src/structures/SeparatorComponent.js +33 -0
  266. package/src/structures/SoundboardSound.js +220 -0
  267. package/src/structures/StageChannel.js +121 -0
  268. package/src/structures/StageInstance.js +170 -0
  269. package/src/structures/Sticker.js +292 -0
  270. package/src/structures/StickerPack.js +107 -0
  271. package/src/structures/StringSelectMenuComponent.js +22 -0
  272. package/src/structures/StringSelectMenuInteraction.js +23 -0
  273. package/src/structures/Subscription.js +131 -0
  274. package/src/structures/Team.js +129 -0
  275. package/src/structures/TeamMember.js +77 -0
  276. package/src/structures/TextChannel.js +36 -0
  277. package/src/structures/TextDisplayComponent.js +22 -0
  278. package/src/structures/TextInputComponent.js +32 -0
  279. package/src/structures/ThreadChannel.js +662 -0
  280. package/src/structures/ThreadMember.js +124 -0
  281. package/src/structures/ThreadOnlyChannel.js +270 -0
  282. package/src/structures/ThumbnailComponent.js +54 -0
  283. package/src/structures/Typing.js +82 -0
  284. package/src/structures/UnfurledMediaItem.js +36 -0
  285. package/src/structures/User.js +505 -0
  286. package/src/structures/UserContextMenuCommandInteraction.js +32 -0
  287. package/src/structures/UserSelectMenuComponent.js +12 -0
  288. package/src/structures/UserSelectMenuInteraction.js +55 -0
  289. package/src/structures/VoiceChannel.js +123 -0
  290. package/src/structures/VoiceChannelEffect.js +88 -0
  291. package/src/structures/VoiceRegion.js +51 -0
  292. package/src/structures/VoiceState.js +338 -0
  293. package/src/structures/Webhook.js +520 -0
  294. package/src/structures/WelcomeChannel.js +67 -0
  295. package/src/structures/WelcomeScreen.js +54 -0
  296. package/src/structures/Widget.js +107 -0
  297. package/src/structures/WidgetMember.js +114 -0
  298. package/src/structures/interfaces/Application.js +173 -0
  299. package/src/structures/interfaces/Collector.js +368 -0
  300. package/src/structures/interfaces/InteractionResponses.js +385 -0
  301. package/src/structures/interfaces/TextBasedChannel.js +431 -0
  302. package/src/util/APITypes.js +700 -0
  303. package/src/util/ActivityFlagsBitField.js +29 -0
  304. package/src/util/ApplicationFlagsBitField.js +46 -0
  305. package/src/util/AttachmentFlagsBitField.js +29 -0
  306. package/src/util/BitField.js +197 -0
  307. package/src/util/ChannelFlagsBitField.js +46 -0
  308. package/src/util/Channels.js +173 -0
  309. package/src/util/Colors.js +73 -0
  310. package/src/util/Components.js +329 -0
  311. package/src/util/Constants.js +253 -0
  312. package/src/util/DataResolver.js +161 -0
  313. package/src/util/Enums.js +14 -0
  314. package/src/util/Events.js +179 -0
  315. package/src/util/GuildMemberFlagsBitField.js +46 -0
  316. package/src/util/IntentsBitField.js +38 -0
  317. package/src/util/InviteFlagsBitField.js +29 -0
  318. package/src/util/Invites.js +31 -0
  319. package/src/util/LimitedCollection.js +75 -0
  320. package/src/util/LolkaSnowflake.js +47 -0
  321. package/src/util/MessageFlagsBitField.js +46 -0
  322. package/src/util/Options.js +221 -0
  323. package/src/util/Partials.js +51 -0
  324. package/src/util/PermissionsBitField.js +117 -0
  325. package/src/util/RoleFlagsBitField.js +29 -0
  326. package/src/util/SKUFlagsBitField.js +29 -0
  327. package/src/util/ShardEvents.js +27 -0
  328. package/src/util/Status.js +17 -0
  329. package/src/util/Sweepers.js +533 -0
  330. package/src/util/Symbols.js +3 -0
  331. package/src/util/SystemChannelFlagsBitField.js +48 -0
  332. package/src/util/ThreadMemberFlagsBitField.js +36 -0
  333. package/src/util/Transformers.js +124 -0
  334. package/src/util/UserFlagsBitField.js +36 -0
  335. package/src/util/Util.js +609 -0
  336. package/typings/index.d.mts +7512 -0
  337. package/typings/index.d.ts +7512 -0
@@ -0,0 +1,1557 @@
1
+ 'use strict';
2
+
3
+ const { Collection } = require('@discordjs/collection');
4
+ const { makeURLSearchParams } = require('@discordjs/rest');
5
+ const { DiscordSnowflake } = require('../util/LolkaSnowflake');
6
+ const { ChannelType, GuildPremiumTier, Routes, GuildFeature } = require('discord-api-types/v10');
7
+ const { DiscordjsError, DiscordjsTypeError, ErrorCodes } = require('../errors/index.js');
8
+ const { AutoModerationRuleManager } = require('../managers/AutoModerationRuleManager.js');
9
+ const { GuildApplicationCommandManager } = require('../managers/GuildApplicationCommandManager.js');
10
+ const { GuildBanManager } = require('../managers/GuildBanManager.js');
11
+ const { GuildChannelManager } = require('../managers/GuildChannelManager.js');
12
+ const { GuildEmojiManager } = require('../managers/GuildEmojiManager.js');
13
+ const { GuildInviteManager } = require('../managers/GuildInviteManager.js');
14
+ const { GuildMemberManager } = require('../managers/GuildMemberManager.js');
15
+ const { GuildScheduledEventManager } = require('../managers/GuildScheduledEventManager.js');
16
+ const { GuildSoundboardSoundManager } = require('../managers/GuildSoundboardSoundManager.js');
17
+ const { GuildStickerManager } = require('../managers/GuildStickerManager.js');
18
+ const { PresenceManager } = require('../managers/PresenceManager.js');
19
+ const { RoleManager } = require('../managers/RoleManager.js');
20
+ const { StageInstanceManager } = require('../managers/StageInstanceManager.js');
21
+ const { VoiceStateManager } = require('../managers/VoiceStateManager.js');
22
+ const { resolveImage } = require('../util/DataResolver.js');
23
+ const { SystemChannelFlagsBitField } = require('../util/SystemChannelFlagsBitField.js');
24
+ const { _transformAPIIncidentsData } = require('../util/Transformers.js');
25
+ const { discordSort, getSortableGroupTypes, resolvePartialEmoji } = require('../util/Util.js');
26
+ const { AnonymousGuild } = require('./AnonymousGuild.js');
27
+ const { GuildAuditLogs } = require('./GuildAuditLogs.js');
28
+ const { GuildOnboarding } = require('./GuildOnboarding.js');
29
+ const { GuildPreview } = require('./GuildPreview.js');
30
+ const { GuildTemplate } = require('./GuildTemplate.js');
31
+ const { Integration } = require('./Integration.js');
32
+ const { Webhook } = require('./Webhook.js');
33
+ const { WelcomeScreen } = require('./WelcomeScreen.js');
34
+
35
+ /**
36
+ * Represents a guild (or a server) on Discord.
37
+ * <info>It's recommended to see if a guild is available before performing operations or reading data from it. You can
38
+ * check this with {@link Guild#available}.</info>
39
+ *
40
+ * @extends {AnonymousGuild}
41
+ */
42
+ class Guild extends AnonymousGuild {
43
+ constructor(client, data) {
44
+ super(client, data, false);
45
+
46
+ /**
47
+ * A manager of the application commands belonging to this guild
48
+ *
49
+ * @type {GuildApplicationCommandManager}
50
+ */
51
+ this.commands = new GuildApplicationCommandManager(this);
52
+
53
+ /**
54
+ * A manager of the members belonging to this guild
55
+ *
56
+ * @type {GuildMemberManager}
57
+ */
58
+ this.members = new GuildMemberManager(this);
59
+
60
+ /**
61
+ * A manager of the channels belonging to this guild
62
+ *
63
+ * @type {GuildChannelManager}
64
+ */
65
+ this.channels = new GuildChannelManager(this);
66
+
67
+ /**
68
+ * A manager of the bans belonging to this guild
69
+ *
70
+ * @type {GuildBanManager}
71
+ */
72
+ this.bans = new GuildBanManager(this);
73
+
74
+ /**
75
+ * A manager of the roles belonging to this guild
76
+ *
77
+ * @type {RoleManager}
78
+ */
79
+ this.roles = new RoleManager(this);
80
+
81
+ /**
82
+ * A manager of the presences belonging to this guild
83
+ *
84
+ * @type {PresenceManager}
85
+ */
86
+ this.presences = new PresenceManager(this.client);
87
+
88
+ /**
89
+ * A manager of the voice states of this guild
90
+ *
91
+ * @type {VoiceStateManager}
92
+ */
93
+ this.voiceStates = new VoiceStateManager(this);
94
+
95
+ /**
96
+ * A manager of the stage instances of this guild
97
+ *
98
+ * @type {StageInstanceManager}
99
+ */
100
+ this.stageInstances = new StageInstanceManager(this);
101
+
102
+ /**
103
+ * A manager of the invites of this guild
104
+ *
105
+ * @type {GuildInviteManager}
106
+ */
107
+ this.invites = new GuildInviteManager(this);
108
+
109
+ /**
110
+ * A manager of the scheduled events of this guild
111
+ *
112
+ * @type {GuildScheduledEventManager}
113
+ */
114
+ this.scheduledEvents = new GuildScheduledEventManager(this);
115
+
116
+ /**
117
+ * A manager of the auto moderation rules of this guild.
118
+ *
119
+ * @type {AutoModerationRuleManager}
120
+ */
121
+ this.autoModerationRules = new AutoModerationRuleManager(this);
122
+
123
+ /**
124
+ * A manager of the soundboard sounds of this guild.
125
+ *
126
+ * @type {GuildSoundboardSoundManager}
127
+ */
128
+ this.soundboardSounds = new GuildSoundboardSoundManager(this);
129
+
130
+ if (!data) return;
131
+ if (data.unavailable) {
132
+ /**
133
+ * Whether the guild is available to access. If it is not available, it indicates a server outage
134
+ *
135
+ * @type {boolean}
136
+ */
137
+ this.available = false;
138
+ } else {
139
+ this._patch(data);
140
+ if (!data.channels) this.available = false;
141
+ }
142
+
143
+ /**
144
+ * The id of the shard this Guild belongs to.
145
+ *
146
+ * @type {number}
147
+ */
148
+ this.shardId = data.shardId;
149
+ }
150
+
151
+ _patch(data) {
152
+ super._patch(data);
153
+ this.id = data.id;
154
+ if ('name' in data) this.name = data.name;
155
+ if ('icon' in data) this.icon = data.icon;
156
+ if ('unavailable' in data) {
157
+ this.available = !data.unavailable;
158
+ } else {
159
+ this.available ??= true;
160
+ }
161
+
162
+ if ('discovery_splash' in data) {
163
+ /**
164
+ * The hash of the guild discovery splash image
165
+ *
166
+ * @type {?string}
167
+ */
168
+ this.discoverySplash = data.discovery_splash;
169
+ }
170
+
171
+ if ('member_count' in data) {
172
+ /**
173
+ * The full amount of members in this guild
174
+ *
175
+ * @type {number}
176
+ */
177
+ this.memberCount = data.member_count;
178
+ }
179
+
180
+ if ('large' in data) {
181
+ /**
182
+ * Whether the guild is "large" (has more than {@link WebSocketOptions large_threshold} members, 50 by default)
183
+ *
184
+ * @type {boolean}
185
+ */
186
+ this.large = Boolean(data.large);
187
+ }
188
+
189
+ if ('premium_progress_bar_enabled' in data) {
190
+ /**
191
+ * Whether this guild has its premium (boost) progress bar enabled
192
+ *
193
+ * @type {boolean}
194
+ */
195
+ this.premiumProgressBarEnabled = data.premium_progress_bar_enabled;
196
+ }
197
+
198
+ if ('application_id' in data) {
199
+ /**
200
+ * The id of the application that created this guild (if applicable)
201
+ *
202
+ * @type {?Snowflake}
203
+ */
204
+ this.applicationId = data.application_id;
205
+ }
206
+
207
+ if ('afk_timeout' in data) {
208
+ /**
209
+ * The time in seconds before a user is counted as "away from keyboard"
210
+ *
211
+ * @type {?number}
212
+ */
213
+ this.afkTimeout = data.afk_timeout;
214
+ }
215
+
216
+ if ('afk_channel_id' in data) {
217
+ /**
218
+ * The id of the voice channel where AFK members are moved
219
+ *
220
+ * @type {?Snowflake}
221
+ */
222
+ this.afkChannelId = data.afk_channel_id;
223
+ }
224
+
225
+ if ('system_channel_id' in data) {
226
+ /**
227
+ * The system channel's id
228
+ *
229
+ * @type {?Snowflake}
230
+ */
231
+ this.systemChannelId = data.system_channel_id;
232
+ }
233
+
234
+ if ('premium_tier' in data) {
235
+ /**
236
+ * The premium tier of this guild
237
+ *
238
+ * @type {GuildPremiumTier}
239
+ */
240
+ this.premiumTier = data.premium_tier;
241
+ }
242
+
243
+ if ('widget_enabled' in data) {
244
+ /**
245
+ * Whether widget images are enabled on this guild
246
+ *
247
+ * @type {?boolean}
248
+ */
249
+ this.widgetEnabled = data.widget_enabled;
250
+ } else {
251
+ this.widgetEnabled ??= null;
252
+ }
253
+
254
+ if ('widget_channel_id' in data) {
255
+ /**
256
+ * The widget channel's id, if enabled
257
+ *
258
+ * @type {?string}
259
+ */
260
+ this.widgetChannelId = data.widget_channel_id;
261
+ } else {
262
+ this.widgetChannelId ??= null;
263
+ }
264
+
265
+ if ('explicit_content_filter' in data) {
266
+ /**
267
+ * The explicit content filter level of the guild
268
+ *
269
+ * @type {GuildExplicitContentFilter}
270
+ */
271
+ this.explicitContentFilter = data.explicit_content_filter;
272
+ }
273
+
274
+ if ('mfa_level' in data) {
275
+ /**
276
+ * The required MFA level for this guild
277
+ *
278
+ * @type {GuildMFALevel}
279
+ */
280
+ this.mfaLevel = data.mfa_level;
281
+ }
282
+
283
+ if ('joined_at' in data) {
284
+ /**
285
+ * The timestamp the client user joined the guild at
286
+ *
287
+ * @type {number}
288
+ */
289
+ this.joinedTimestamp = Date.parse(data.joined_at);
290
+ }
291
+
292
+ if ('default_message_notifications' in data) {
293
+ /**
294
+ * The default message notification level of the guild
295
+ *
296
+ * @type {GuildDefaultMessageNotifications}
297
+ */
298
+ this.defaultMessageNotifications = data.default_message_notifications;
299
+ }
300
+
301
+ if ('system_channel_flags' in data) {
302
+ /**
303
+ * The value set for the guild's system channel flags
304
+ *
305
+ * @type {Readonly<SystemChannelFlagsBitField>}
306
+ */
307
+ this.systemChannelFlags = new SystemChannelFlagsBitField(data.system_channel_flags).freeze();
308
+ }
309
+
310
+ if ('max_members' in data) {
311
+ /**
312
+ * The maximum amount of members the guild can have
313
+ *
314
+ * @type {?number}
315
+ */
316
+ this.maximumMembers = data.max_members;
317
+ } else {
318
+ this.maximumMembers ??= null;
319
+ }
320
+
321
+ if ('max_presences' in data) {
322
+ /**
323
+ * The maximum amount of presences the guild can have (this is `null` for all but the largest of guilds)
324
+ * <info>You will need to fetch the guild using {@link BaseGuild#fetch} if you want to receive
325
+ * this parameter</info>
326
+ *
327
+ * @type {?number}
328
+ */
329
+ this.maximumPresences = data.max_presences;
330
+ } else {
331
+ this.maximumPresences ??= null;
332
+ }
333
+
334
+ if ('max_video_channel_users' in data) {
335
+ /**
336
+ * The maximum amount of users allowed in a video channel.
337
+ *
338
+ * @type {?number}
339
+ */
340
+ this.maxVideoChannelUsers = data.max_video_channel_users;
341
+ } else {
342
+ this.maxVideoChannelUsers ??= null;
343
+ }
344
+
345
+ if ('max_stage_video_channel_users' in data) {
346
+ /**
347
+ * The maximum amount of users allowed in a stage video channel.
348
+ *
349
+ * @type {?number}
350
+ */
351
+ this.maxStageVideoChannelUsers = data.max_stage_video_channel_users;
352
+ } else {
353
+ this.maxStageVideoChannelUsers ??= null;
354
+ }
355
+
356
+ if ('approximate_member_count' in data) {
357
+ /**
358
+ * The approximate amount of members the guild has
359
+ * <info>You will need to fetch the guild using {@link BaseGuild#fetch} if you want to receive
360
+ * this parameter</info>
361
+ *
362
+ * @type {?number}
363
+ */
364
+ this.approximateMemberCount = data.approximate_member_count;
365
+ } else {
366
+ this.approximateMemberCount ??= null;
367
+ }
368
+
369
+ if ('approximate_presence_count' in data) {
370
+ /**
371
+ * The approximate amount of presences the guild has
372
+ * <info>You will need to fetch the guild using {@link BaseGuild#fetch} if you want to receive
373
+ * this parameter</info>
374
+ *
375
+ * @type {?number}
376
+ */
377
+ this.approximatePresenceCount = data.approximate_presence_count;
378
+ } else {
379
+ this.approximatePresenceCount ??= null;
380
+ }
381
+
382
+ /**
383
+ * The use count of the vanity URL code of the guild, if any
384
+ * <info>You will need to fetch this parameter using {@link Guild#fetchVanityData} if you want to receive it</info>
385
+ *
386
+ * @type {?number}
387
+ */
388
+ this.vanityURLUses ??= null;
389
+
390
+ if ('rules_channel_id' in data) {
391
+ /**
392
+ * The rules channel's id for the guild
393
+ *
394
+ * @type {?Snowflake}
395
+ */
396
+ this.rulesChannelId = data.rules_channel_id;
397
+ }
398
+
399
+ if ('public_updates_channel_id' in data) {
400
+ /**
401
+ * The community updates channel's id for the guild
402
+ *
403
+ * @type {?Snowflake}
404
+ */
405
+ this.publicUpdatesChannelId = data.public_updates_channel_id;
406
+ }
407
+
408
+ if ('preferred_locale' in data) {
409
+ /**
410
+ * The preferred locale of the guild, defaults to `en-US`
411
+ *
412
+ * @type {Locale}
413
+ */
414
+ this.preferredLocale = data.preferred_locale;
415
+ }
416
+
417
+ if ('safety_alerts_channel_id' in data) {
418
+ /**
419
+ * The safety alerts channel's id for the guild
420
+ *
421
+ * @type {?Snowflake}
422
+ */
423
+ this.safetyAlertsChannelId = data.safety_alerts_channel_id;
424
+ } else {
425
+ this.safetyAlertsChannelId ??= null;
426
+ }
427
+
428
+ if (data.channels) {
429
+ this.channels.cache.clear();
430
+ for (const rawChannel of data.channels) {
431
+ this.client.channels._add(rawChannel, this);
432
+ }
433
+ }
434
+
435
+ if (data.threads) {
436
+ for (const rawThread of data.threads) {
437
+ this.client.channels._add(rawThread, this);
438
+ }
439
+ }
440
+
441
+ if (data.roles) {
442
+ this.roles.cache.clear();
443
+ for (const role of data.roles) this.roles._add(role);
444
+ }
445
+
446
+ if (data.members) {
447
+ this.members.cache.clear();
448
+ for (const guildUser of data.members) this.members._add(guildUser);
449
+ }
450
+
451
+ if ('owner_id' in data) {
452
+ /**
453
+ * The user id of this guild's owner
454
+ *
455
+ * @type {Snowflake}
456
+ */
457
+ this.ownerId = data.owner_id;
458
+ }
459
+
460
+ if (data.presences) {
461
+ for (const presence of data.presences) {
462
+ this.presences._add(Object.assign(presence, { guild: this }));
463
+ }
464
+ }
465
+
466
+ if (data.stage_instances) {
467
+ this.stageInstances.cache.clear();
468
+ for (const stageInstance of data.stage_instances) {
469
+ this.stageInstances._add(stageInstance);
470
+ }
471
+ }
472
+
473
+ if (data.guild_scheduled_events) {
474
+ this.scheduledEvents.cache.clear();
475
+ for (const scheduledEvent of data.guild_scheduled_events) {
476
+ this.scheduledEvents._add(scheduledEvent);
477
+ }
478
+ }
479
+
480
+ if (data.voice_states) {
481
+ this.voiceStates.cache.clear();
482
+ for (const voiceState of data.voice_states) {
483
+ this.voiceStates._add(voiceState);
484
+ }
485
+ }
486
+
487
+ if (!this.emojis) {
488
+ /**
489
+ * A manager of the emojis belonging to this guild
490
+ *
491
+ * @type {GuildEmojiManager}
492
+ */
493
+ this.emojis = new GuildEmojiManager(this);
494
+ if (data.emojis) for (const emoji of data.emojis) this.emojis._add(emoji);
495
+ } else if (data.emojis) {
496
+ this.client.actions.GuildEmojisUpdate.handle({
497
+ guild_id: this.id,
498
+ emojis: data.emojis,
499
+ });
500
+ }
501
+
502
+ if (!this.stickers) {
503
+ /**
504
+ * A manager of the stickers belonging to this guild
505
+ *
506
+ * @type {GuildStickerManager}
507
+ */
508
+ this.stickers = new GuildStickerManager(this);
509
+ if (data.stickers) for (const sticker of data.stickers) this.stickers._add(sticker);
510
+ } else if (data.stickers) {
511
+ this.client.actions.GuildStickersUpdate.handle({
512
+ guild_id: this.id,
513
+ stickers: data.stickers,
514
+ });
515
+ }
516
+
517
+ if ('incidents_data' in data) {
518
+ /**
519
+ * Incident actions of a guild.
520
+ *
521
+ * @typedef {Object} IncidentActions
522
+ * @property {?Date} invitesDisabledUntil When invites would be enabled again
523
+ * @property {?Date} dmsDisabledUntil When direct messages would be enabled again
524
+ * @property {?Date} dmSpamDetectedAt When direct message spam was detected
525
+ * @property {?Date} raidDetectedAt When a raid was detected
526
+ */
527
+
528
+ /**
529
+ * The incidents data of this guild.
530
+ * <info>You will need to fetch the guild using {@link BaseGuild#fetch} if you want to receive
531
+ * this property.</info>
532
+ *
533
+ * @type {?IncidentActions}
534
+ */
535
+ this.incidentsData = data.incidents_data && _transformAPIIncidentsData(data.incidents_data);
536
+ } else {
537
+ this.incidentsData ??= null;
538
+ }
539
+
540
+ if (data.soundboard_sounds) {
541
+ this.soundboardSounds.cache.clear();
542
+ for (const soundboardSound of data.soundboard_sounds) {
543
+ this.soundboardSounds._add(soundboardSound);
544
+ }
545
+ }
546
+ }
547
+
548
+ /**
549
+ * The time the client user joined the guild
550
+ *
551
+ * @type {Date}
552
+ * @readonly
553
+ */
554
+ get joinedAt() {
555
+ return new Date(this.joinedTimestamp);
556
+ }
557
+
558
+ /**
559
+ * The URL to this guild's discovery splash image.
560
+ *
561
+ * @param {ImageURLOptions} [options={}] Options for the image URL
562
+ * @returns {?string}
563
+ */
564
+ discoverySplashURL(options = {}) {
565
+ return this.discoverySplash && (/^https?:\/\//.test(this.discoverySplash) ? this.discoverySplash : this.client.rest.cdn.discoverySplash(this.id, this.discoverySplash, options));
566
+ }
567
+
568
+ /**
569
+ * Fetches the owner of the guild.
570
+ * If the member object isn't needed, use {@link Guild#ownerId} instead.
571
+ *
572
+ * @param {BaseFetchOptions} [options] The options for fetching the member
573
+ * @returns {Promise<GuildMember>}
574
+ */
575
+ async fetchOwner(options) {
576
+ if (!this.ownerId) {
577
+ throw new DiscordjsError(ErrorCodes.FetchOwnerId, 'guild');
578
+ }
579
+
580
+ return this.members.fetch({ ...options, user: this.ownerId });
581
+ }
582
+
583
+ /**
584
+ * AFK voice channel for this guild
585
+ *
586
+ * @type {?VoiceChannel}
587
+ * @readonly
588
+ */
589
+ get afkChannel() {
590
+ return this.client.channels.resolve(this.afkChannelId);
591
+ }
592
+
593
+ /**
594
+ * System channel for this guild
595
+ *
596
+ * @type {?TextChannel}
597
+ * @readonly
598
+ */
599
+ get systemChannel() {
600
+ return this.client.channels.resolve(this.systemChannelId);
601
+ }
602
+
603
+ /**
604
+ * Widget channel for this guild
605
+ *
606
+ * @type {?(TextChannel|AnnouncementChannel|VoiceChannel|StageChannel|ForumChannel|MediaChannel)}
607
+ * @readonly
608
+ */
609
+ get widgetChannel() {
610
+ return this.client.channels.resolve(this.widgetChannelId);
611
+ }
612
+
613
+ /**
614
+ * Rules channel for this guild
615
+ *
616
+ * @type {?TextChannel}
617
+ * @readonly
618
+ */
619
+ get rulesChannel() {
620
+ return this.client.channels.resolve(this.rulesChannelId);
621
+ }
622
+
623
+ /**
624
+ * Public updates channel for this guild
625
+ *
626
+ * @type {?TextChannel}
627
+ * @readonly
628
+ */
629
+ get publicUpdatesChannel() {
630
+ return this.client.channels.resolve(this.publicUpdatesChannelId);
631
+ }
632
+
633
+ /**
634
+ * Safety alerts channel for this guild
635
+ *
636
+ * @type {?TextChannel}
637
+ * @readonly
638
+ */
639
+ get safetyAlertsChannel() {
640
+ return this.client.channels.resolve(this.safetyAlertsChannelId);
641
+ }
642
+
643
+ /**
644
+ * The maximum bitrate available for a voice channel in this guild
645
+ *
646
+ * @type {number}
647
+ * @readonly
648
+ */
649
+ get maximumBitrate() {
650
+ if (this.features.includes(GuildFeature.VIPRegions)) {
651
+ return 384_000;
652
+ }
653
+
654
+ switch (this.premiumTier) {
655
+ case GuildPremiumTier.Tier1:
656
+ return 128_000;
657
+ case GuildPremiumTier.Tier2:
658
+ return 256_000;
659
+ case GuildPremiumTier.Tier3:
660
+ return 384_000;
661
+ default:
662
+ return 96_000;
663
+ }
664
+ }
665
+
666
+ /**
667
+ * The maximum bitrate available for a stage channel in this guild
668
+ *
669
+ * @type {number}
670
+ * @readonly
671
+ */
672
+ get maximumStageBitrate() {
673
+ return 64_000;
674
+ }
675
+
676
+ /**
677
+ * Fetches a collection of integrations to this guild.
678
+ * Resolves with a collection mapping integrations by their ids.
679
+ *
680
+ * @returns {Promise<Collection<Snowflake|string, Integration>>}
681
+ * @example
682
+ * // Fetch integrations
683
+ * guild.fetchIntegrations()
684
+ * .then(integrations => console.log(`Fetched ${integrations.size} integrations`))
685
+ * .catch(console.error);
686
+ */
687
+ async fetchIntegrations() {
688
+ const data = await this.client.rest.get(Routes.guildIntegrations(this.id));
689
+ return data.reduce(
690
+ (collection, integration) => collection.set(integration.id, new Integration(this.client, integration, this)),
691
+ new Collection(),
692
+ );
693
+ }
694
+
695
+ /**
696
+ * Fetches a collection of templates from this guild.
697
+ * Resolves with a collection mapping templates by their codes.
698
+ *
699
+ * @returns {Promise<Collection<string, GuildTemplate>>}
700
+ */
701
+ async fetchTemplates() {
702
+ const templates = await this.client.rest.get(Routes.guildTemplates(this.id));
703
+ return templates.reduce((col, data) => col.set(data.code, new GuildTemplate(this.client, data)), new Collection());
704
+ }
705
+
706
+ /**
707
+ * Fetches the welcome screen for this guild.
708
+ *
709
+ * @returns {Promise<WelcomeScreen>}
710
+ */
711
+ async fetchWelcomeScreen() {
712
+ const data = await this.client.rest.get(Routes.guildWelcomeScreen(this.id));
713
+ return new WelcomeScreen(this, data);
714
+ }
715
+
716
+ /**
717
+ * Creates a template for the guild.
718
+ *
719
+ * @param {string} name The name for the template
720
+ * @param {string} [description] The description for the template
721
+ * @returns {Promise<GuildTemplate>}
722
+ */
723
+ async createTemplate(name, description) {
724
+ const data = await this.client.rest.post(Routes.guildTemplates(this.id), { body: { name, description } });
725
+ return new GuildTemplate(this.client, data);
726
+ }
727
+
728
+ /**
729
+ * Obtains a guild preview for this guild from Discord.
730
+ *
731
+ * @returns {Promise<GuildPreview>}
732
+ */
733
+ async fetchPreview() {
734
+ const data = await this.client.rest.get(Routes.guildPreview(this.id));
735
+ return new GuildPreview(this.client, data);
736
+ }
737
+
738
+ /**
739
+ * An object containing information about a guild's vanity invite.
740
+ *
741
+ * @typedef {Object} Vanity
742
+ * @property {?string} code Vanity invite code
743
+ * @property {number} uses How many times this invite has been used
744
+ */
745
+
746
+ /**
747
+ * Fetches the vanity URL invite object to this guild.
748
+ * Resolves with an object containing the vanity URL invite code and the use count
749
+ *
750
+ * @returns {Promise<Vanity>}
751
+ * @example
752
+ * // Fetch invite data
753
+ * guild.fetchVanityData()
754
+ * .then(res => {
755
+ * console.log(`Vanity URL: https://discord.gg/${res.code} with ${res.uses} uses`);
756
+ * })
757
+ * .catch(console.error);
758
+ */
759
+ async fetchVanityData() {
760
+ const data = await this.client.rest.get(Routes.guildVanityUrl(this.id));
761
+ this.vanityURLCode = data.code;
762
+ this.vanityURLUses = data.uses;
763
+
764
+ return data;
765
+ }
766
+
767
+ /**
768
+ * Fetches all webhooks for the guild.
769
+ *
770
+ * @returns {Promise<Collection<Snowflake, Webhook>>}
771
+ * @example
772
+ * // Fetch webhooks
773
+ * guild.fetchWebhooks()
774
+ * .then(webhooks => console.log(`Fetched ${webhooks.size} webhooks`))
775
+ * .catch(console.error);
776
+ */
777
+ async fetchWebhooks() {
778
+ const apiHooks = await this.client.rest.get(Routes.guildWebhooks(this.id));
779
+ const hooks = new Collection();
780
+ for (const hook of apiHooks) hooks.set(hook.id, new Webhook(this.client, hook));
781
+ return hooks;
782
+ }
783
+
784
+ /**
785
+ * Fetches the guild widget data, requires the widget to be enabled.
786
+ *
787
+ * @returns {Promise<Widget>}
788
+ * @example
789
+ * // Fetches the guild widget data
790
+ * guild.fetchWidget()
791
+ * .then(widget => console.log(`The widget shows ${widget.channels.size} channels`))
792
+ * .catch(console.error);
793
+ */
794
+ async fetchWidget() {
795
+ return this.client.fetchGuildWidget(this.id);
796
+ }
797
+
798
+ /**
799
+ * Data for the Guild Widget Settings object
800
+ *
801
+ * @typedef {Object} GuildWidgetSettings
802
+ * @property {boolean} enabled Whether the widget is enabled
803
+ * @property {?(TextChannel|AnnouncementChannel|VoiceChannel|StageChannel|ForumChannel|MediaChannel)} channel
804
+ * The widget invite channel
805
+ */
806
+
807
+ /**
808
+ * The Guild Widget Settings object
809
+ *
810
+ * @typedef {Object} GuildWidgetSettingsData
811
+ * @property {boolean} enabled Whether the widget is enabled
812
+ * @property {?(TextChannel|AnnouncementChannel|VoiceChannel|StageChannel|ForumChannel|
813
+ * MediaChannel|Snowflake)} channel The widget invite channel
814
+ */
815
+
816
+ /**
817
+ * Fetches the guild widget settings.
818
+ *
819
+ * @returns {Promise<GuildWidgetSettings>}
820
+ * @example
821
+ * // Fetches the guild widget settings
822
+ * guild.fetchWidgetSettings()
823
+ * .then(widget => console.log(`The widget is ${widget.enabled ? 'enabled' : 'disabled'}`))
824
+ * .catch(console.error);
825
+ */
826
+ async fetchWidgetSettings() {
827
+ const data = await this.client.rest.get(Routes.guildWidgetSettings(this.id));
828
+ this.widgetEnabled = data.enabled;
829
+ this.widgetChannelId = data.channel_id;
830
+ return {
831
+ enabled: data.enabled,
832
+ channel: data.channel_id ? this.channels.cache.get(data.channel_id) : null,
833
+ };
834
+ }
835
+
836
+ /**
837
+ * Returns a URL for the PNG widget of the guild.
838
+ *
839
+ * @param {GuildWidgetStyle} [style] The style for the widget image
840
+ * @returns {string}
841
+ */
842
+ widgetImageURL(style) {
843
+ return this.client.guilds.widgetImageURL(this.id, style);
844
+ }
845
+
846
+ /**
847
+ * Options used to fetch audit logs.
848
+ *
849
+ * @typedef {Object} GuildAuditLogsFetchOptions
850
+ * @property {Snowflake|GuildAuditLogsEntry} [before] Consider only entries before this entry
851
+ * @property {Snowflake|GuildAuditLogsEntry} [after] Consider only entries after this entry
852
+ * @property {number} [limit] The number of entries to return
853
+ * @property {UserResolvable} [user] Only return entries for actions made by this user
854
+ * @property {?AuditLogEvent} [type] Only return entries for this action type
855
+ */
856
+
857
+ /**
858
+ * Fetches audit logs for this guild.
859
+ *
860
+ * @param {GuildAuditLogsFetchOptions} [options={}] Options for fetching audit logs
861
+ * @returns {Promise<GuildAuditLogs>}
862
+ * @example
863
+ * // Output audit log entries
864
+ * guild.fetchAuditLogs()
865
+ * .then(audit => console.log(audit.entries.first()))
866
+ * .catch(console.error);
867
+ */
868
+ async fetchAuditLogs({ before, after, limit, user, type } = {}) {
869
+ const query = makeURLSearchParams({
870
+ before: before?.id ?? before,
871
+ after: after?.id ?? after,
872
+ limit,
873
+ action_type: type,
874
+ });
875
+
876
+ if (user) {
877
+ const userId = this.client.users.resolveId(user);
878
+ if (!userId) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'user', 'UserResolvable');
879
+ query.set('user_id', userId);
880
+ }
881
+
882
+ const data = await this.client.rest.get(Routes.guildAuditLog(this.id), { query });
883
+ return new GuildAuditLogs(this, data);
884
+ }
885
+
886
+ /**
887
+ * Fetches the guild onboarding data for this guild.
888
+ *
889
+ * @returns {Promise<GuildOnboarding>}
890
+ */
891
+ async fetchOnboarding() {
892
+ const data = await this.client.rest.get(Routes.guildOnboarding(this.id));
893
+ return new GuildOnboarding(this.client, data);
894
+ }
895
+
896
+ /**
897
+ * The data for editing a guild.
898
+ *
899
+ * @typedef {Object} GuildEditOptions
900
+ * @property {string} [name] The name of the guild
901
+ * @property {?GuildVerificationLevel} [verificationLevel] The verification level of the guild
902
+ * @property {?GuildDefaultMessageNotifications} [defaultMessageNotifications] The default message
903
+ * notification level of the guild
904
+ * @property {?GuildExplicitContentFilter} [explicitContentFilter] The level of the explicit content filter
905
+ * @property {?VoiceChannelResolvable} [afkChannel] The AFK channel of the guild
906
+ * @property {number} [afkTimeout] The AFK timeout of the guild
907
+ * @property {?(BufferResolvable|Base64Resolvable)} [icon] The icon of the guild
908
+ * @property {?(BufferResolvable|Base64Resolvable)} [splash] The invite splash image of the guild
909
+ * @property {?(BufferResolvable|Base64Resolvable)} [discoverySplash] The discovery splash image of the guild
910
+ * @property {?(BufferResolvable|Base64Resolvable)} [banner] The banner of the guild
911
+ * @property {?TextChannelResolvable} [systemChannel] The system channel of the guild
912
+ * @property {SystemChannelFlagsResolvable} [systemChannelFlags] The system channel flags of the guild
913
+ * @property {?TextChannelResolvable} [rulesChannel] The rules channel of the guild
914
+ * @property {?TextChannelResolvable} [publicUpdatesChannel] The community updates channel of the guild
915
+ * @property {?TextChannelResolvable} [safetyAlertsChannel] The safety alerts channel of the guild
916
+ * @property {?string} [preferredLocale] The preferred locale of the guild
917
+ * @property {GuildFeature[]} [features] The features of the guild
918
+ * @property {?string} [description] The discovery description of the guild
919
+ * @property {boolean} [premiumProgressBarEnabled] Whether the guild's premium progress bar is enabled
920
+ * @property {string} [reason] Reason for editing this guild
921
+ */
922
+
923
+ /**
924
+ * Data that can be resolved to a Text Channel object. This can be:
925
+ * - A TextChannel
926
+ * - A Snowflake
927
+ *
928
+ * @typedef {TextChannel|Snowflake} TextChannelResolvable
929
+ */
930
+
931
+ /**
932
+ * Data that can be resolved to a Voice Channel object. This can be:
933
+ * - A VoiceChannel
934
+ * - A Snowflake
935
+ *
936
+ * @typedef {VoiceChannel|Snowflake} VoiceChannelResolvable
937
+ */
938
+
939
+ /**
940
+ * Updates the guild with new information - e.g. a new name.
941
+ *
942
+ * @param {GuildEditOptions} options The options to provide
943
+ * @returns {Promise<Guild>}
944
+ * @example
945
+ * // Set the guild name
946
+ * guild.edit({
947
+ * name: 'Discord Guild',
948
+ * })
949
+ * .then(updated => console.log(`New guild name ${updated}`))
950
+ * .catch(console.error);
951
+ */
952
+ async edit({
953
+ verificationLevel,
954
+ defaultMessageNotifications,
955
+ explicitContentFilter,
956
+ afkChannel,
957
+ afkTimeout,
958
+ icon,
959
+ splash,
960
+ discoverySplash,
961
+ banner,
962
+ systemChannel,
963
+ systemChannelFlags,
964
+ rulesChannel,
965
+ publicUpdatesChannel,
966
+ preferredLocale,
967
+ premiumProgressBarEnabled,
968
+ safetyAlertsChannel,
969
+ ...options
970
+ }) {
971
+ const data = await this.client.rest.patch(Routes.guild(this.id), {
972
+ body: {
973
+ ...options,
974
+ verification_level: verificationLevel,
975
+ default_message_notifications: defaultMessageNotifications,
976
+ explicit_content_filter: explicitContentFilter,
977
+ afk_channel_id: afkChannel && this.client.channels.resolveId(afkChannel),
978
+ afk_timeout: afkTimeout,
979
+ icon: icon && (await resolveImage(icon)),
980
+ splash: splash && (await resolveImage(splash)),
981
+ discovery_splash: discoverySplash && (await resolveImage(discoverySplash)),
982
+ banner: banner && (await resolveImage(banner)),
983
+ system_channel_id: systemChannel && this.client.channels.resolveId(systemChannel),
984
+ system_channel_flags:
985
+ systemChannelFlags === undefined ? undefined : SystemChannelFlagsBitField.resolve(systemChannelFlags),
986
+ rules_channel_id: rulesChannel && this.client.channels.resolveId(rulesChannel),
987
+ public_updates_channel_id: publicUpdatesChannel && this.client.channels.resolveId(publicUpdatesChannel),
988
+ preferred_locale: preferredLocale,
989
+ premium_progress_bar_enabled: premiumProgressBarEnabled,
990
+ safety_alerts_channel_id: safetyAlertsChannel && this.client.channels.resolveId(safetyAlertsChannel),
991
+ },
992
+ reason: options.reason,
993
+ });
994
+
995
+ return this.client.actions.GuildUpdate.handle(data).updated;
996
+ }
997
+
998
+ /**
999
+ * Options used to edit the guild onboarding.
1000
+ *
1001
+ * @typedef {Object} GuildOnboardingEditOptions
1002
+ * @property {GuildOnboardingPromptData[]|Collection<Snowflake, GuildOnboardingPrompt>} [prompts]
1003
+ * The prompts shown during onboarding and in customize community
1004
+ * @property {ChannelResolvable[]|Collection<Snowflake, GuildChannel>} [defaultChannels]
1005
+ * The channels that new members get opted into automatically
1006
+ * @property {boolean} [enabled] Whether the onboarding is enabled
1007
+ * @property {GuildOnboardingMode} [mode] The mode to edit the guild onboarding with
1008
+ * @property {string} [reason] The reason for editing the guild onboarding
1009
+ */
1010
+
1011
+ /**
1012
+ * Data for editing a guild onboarding prompt.
1013
+ *
1014
+ * @typedef {Object} GuildOnboardingPromptData
1015
+ * @property {Snowflake} [id] The id of the prompt
1016
+ * @property {string} title The title for the prompt
1017
+ * @property {boolean} [singleSelect] Whether users are limited to selecting one option for the prompt
1018
+ * @property {boolean} [required] Whether the prompt is required before a user completes the onboarding flow
1019
+ * @property {boolean} [inOnboarding] Whether the prompt is present in the onboarding flow
1020
+ * @property {GuildOnboardingPromptType} [type] The type of the prompt
1021
+ * @property {GuildOnboardingPromptOptionData[]|Collection<Snowflake, GuildOnboardingPrompt>} options
1022
+ * The options available within the prompt
1023
+ */
1024
+
1025
+ /**
1026
+ * Data for editing a guild onboarding prompt option.
1027
+ *
1028
+ * @typedef {Object} GuildOnboardingPromptOptionData
1029
+ * @property {?Snowflake} [id] The id of the option
1030
+ * @property {ChannelResolvable[]|Collection<Snowflake, GuildChannel>} [channels]
1031
+ * The channels a member is added to when the option is selected
1032
+ * @property {RoleResolvable[]|Collection<Snowflake, Role>} [roles]
1033
+ * The roles assigned to a member when the option is selected
1034
+ * @property {string} title The title of the option
1035
+ * @property {?string} [description] The description of the option
1036
+ * @property {?(EmojiIdentifierResolvable|Emoji)} [emoji] The emoji of the option
1037
+ */
1038
+
1039
+ /**
1040
+ * Edits the guild onboarding data for this guild.
1041
+ *
1042
+ * @param {GuildOnboardingEditOptions} options The options to provide
1043
+ * @returns {Promise<GuildOnboarding>}
1044
+ */
1045
+ async editOnboarding(options) {
1046
+ const newData = await this.client.rest.put(Routes.guildOnboarding(this.id), {
1047
+ body: {
1048
+ prompts: options.prompts?.map(prompt => ({
1049
+ // Currently, the prompt ids are required even for new ones (which won't be used)
1050
+ id: prompt.id ?? DiscordSnowflake.generate().toString(),
1051
+ title: prompt.title,
1052
+ single_select: prompt.singleSelect,
1053
+ required: prompt.required,
1054
+ in_onboarding: prompt.inOnboarding,
1055
+ type: prompt.type,
1056
+ options: prompt.options.map(option => {
1057
+ const emoji = resolvePartialEmoji(option.emoji);
1058
+
1059
+ return {
1060
+ id: option.id,
1061
+ channel_ids: option.channels?.map(channel => this.channels.resolveId(channel)),
1062
+ role_ids: option.roles?.map(role => this.roles.resolveId(role)),
1063
+ title: option.title,
1064
+ description: option.description,
1065
+ emoji_animated: emoji?.animated,
1066
+ emoji_id: emoji?.id,
1067
+ emoji_name: emoji?.name,
1068
+ };
1069
+ }),
1070
+ })),
1071
+ default_channel_ids: options.defaultChannels?.map(channel => this.channels.resolveId(channel)),
1072
+ enabled: options.enabled,
1073
+ mode: options.mode,
1074
+ },
1075
+ reason: options.reason,
1076
+ });
1077
+
1078
+ return new GuildOnboarding(this.client, newData);
1079
+ }
1080
+
1081
+ /**
1082
+ * Welcome channel data
1083
+ *
1084
+ * @typedef {Object} WelcomeChannelData
1085
+ * @property {string} description The description to show for this welcome channel
1086
+ * @property {TextChannel|AnnouncementChannel|ForumChannel|MediaChannel|Snowflake} channel
1087
+ * The channel to link for this welcome channel
1088
+ * @property {EmojiIdentifierResolvable} [emoji] The emoji to display for this welcome channel
1089
+ */
1090
+
1091
+ /**
1092
+ * Welcome screen edit data
1093
+ *
1094
+ * @typedef {Object} WelcomeScreenEditOptions
1095
+ * @property {boolean} [enabled] Whether the welcome screen is enabled
1096
+ * @property {string} [description] The description for the welcome screen
1097
+ * @property {WelcomeChannelData[]} [welcomeChannels] The welcome channel data for the welcome screen
1098
+ */
1099
+
1100
+ /**
1101
+ * Data that can be resolved to a GuildTextChannel object. This can be:
1102
+ * - A TextChannel
1103
+ * - A AnnouncementChannel
1104
+ * - A Snowflake
1105
+ *
1106
+ * @typedef {TextChannel|AnnouncementChannel|Snowflake} GuildTextChannelResolvable
1107
+ */
1108
+
1109
+ /**
1110
+ * Data that can be resolved to a GuildVoiceChannel object. This can be:
1111
+ * - A VoiceChannel
1112
+ * - A StageChannel
1113
+ * - A Snowflake
1114
+ *
1115
+ * @typedef {VoiceChannel|StageChannel|Snowflake} GuildVoiceChannelResolvable
1116
+ */
1117
+
1118
+ /**
1119
+ * Updates the guild's welcome screen
1120
+ *
1121
+ * @param {WelcomeScreenEditOptions} options The options to provide
1122
+ * @returns {Promise<WelcomeScreen>}
1123
+ * @example
1124
+ * guild.editWelcomeScreen({
1125
+ * description: 'Hello World',
1126
+ * enabled: true,
1127
+ * welcomeChannels: [
1128
+ * {
1129
+ * description: 'foobar',
1130
+ * channel: '222197033908436994',
1131
+ * }
1132
+ * ],
1133
+ * })
1134
+ */
1135
+ async editWelcomeScreen(options) {
1136
+ const { enabled, description, welcomeChannels } = options;
1137
+ const welcome_channels = welcomeChannels?.map(welcomeChannelData => {
1138
+ const emoji = this.emojis.resolve(welcomeChannelData.emoji);
1139
+ return {
1140
+ emoji_id: emoji?.id,
1141
+ emoji_name: emoji?.name ?? welcomeChannelData.emoji,
1142
+ channel_id: this.channels.resolveId(welcomeChannelData.channel),
1143
+ description: welcomeChannelData.description,
1144
+ };
1145
+ });
1146
+
1147
+ const patchData = await this.client.rest.patch(Routes.guildWelcomeScreen(this.id), {
1148
+ body: {
1149
+ welcome_channels,
1150
+ description,
1151
+ enabled,
1152
+ },
1153
+ });
1154
+ return new WelcomeScreen(this, patchData);
1155
+ }
1156
+
1157
+ /**
1158
+ * Edits the level of the explicit content filter.
1159
+ *
1160
+ * @param {?GuildExplicitContentFilter} explicitContentFilter The new level of the explicit content filter
1161
+ * @param {string} [reason] Reason for changing the level of the guild's explicit content filter
1162
+ * @returns {Promise<Guild>}
1163
+ */
1164
+ async setExplicitContentFilter(explicitContentFilter, reason) {
1165
+ return this.edit({ explicitContentFilter, reason });
1166
+ }
1167
+
1168
+ /**
1169
+ * Edits the setting of the default message notifications of the guild.
1170
+ *
1171
+ * @param {?GuildDefaultMessageNotifications} defaultMessageNotifications
1172
+ * The new default message notification level of the guild
1173
+ * @param {string} [reason] Reason for changing the setting of the default message notifications
1174
+ * @returns {Promise<Guild>}
1175
+ */
1176
+ async setDefaultMessageNotifications(defaultMessageNotifications, reason) {
1177
+ return this.edit({ defaultMessageNotifications, reason });
1178
+ }
1179
+
1180
+ /**
1181
+ * Edits the flags of the default message notifications of the guild.
1182
+ *
1183
+ * @param {SystemChannelFlagsResolvable} systemChannelFlags The new flags for the default message notifications
1184
+ * @param {string} [reason] Reason for changing the flags of the default message notifications
1185
+ * @returns {Promise<Guild>}
1186
+ */
1187
+ async setSystemChannelFlags(systemChannelFlags, reason) {
1188
+ return this.edit({ systemChannelFlags, reason });
1189
+ }
1190
+
1191
+ /**
1192
+ * Edits the name of the guild.
1193
+ *
1194
+ * @param {string} name The new name of the guild
1195
+ * @param {string} [reason] Reason for changing the guild's name
1196
+ * @returns {Promise<Guild>}
1197
+ * @example
1198
+ * // Edit the guild name
1199
+ * guild.setName('Discord Guild')
1200
+ * .then(updated => console.log(`Updated guild name to ${updated.name}`))
1201
+ * .catch(console.error);
1202
+ */
1203
+ async setName(name, reason) {
1204
+ return this.edit({ name, reason });
1205
+ }
1206
+
1207
+ /**
1208
+ * Edits the verification level of the guild.
1209
+ *
1210
+ * @param {?GuildVerificationLevel} verificationLevel The new verification level of the guild
1211
+ * @param {string} [reason] Reason for changing the guild's verification level
1212
+ * @returns {Promise<Guild>}
1213
+ * @example
1214
+ * // Edit the guild verification level
1215
+ * guild.setVerificationLevel(1)
1216
+ * .then(updated => console.log(`Updated guild verification level to ${guild.verificationLevel}`))
1217
+ * .catch(console.error);
1218
+ */
1219
+ async setVerificationLevel(verificationLevel, reason) {
1220
+ return this.edit({ verificationLevel, reason });
1221
+ }
1222
+
1223
+ /**
1224
+ * Edits the AFK channel of the guild.
1225
+ *
1226
+ * @param {?VoiceChannelResolvable} afkChannel The new AFK channel
1227
+ * @param {string} [reason] Reason for changing the guild's AFK channel
1228
+ * @returns {Promise<Guild>}
1229
+ * @example
1230
+ * // Edit the guild AFK channel
1231
+ * guild.setAFKChannel(channel)
1232
+ * .then(updated => console.log(`Updated guild AFK channel to ${guild.afkChannel.name}`))
1233
+ * .catch(console.error);
1234
+ */
1235
+ async setAFKChannel(afkChannel, reason) {
1236
+ return this.edit({ afkChannel, reason });
1237
+ }
1238
+
1239
+ /**
1240
+ * Edits the system channel of the guild.
1241
+ *
1242
+ * @param {?TextChannelResolvable} systemChannel The new system channel
1243
+ * @param {string} [reason] Reason for changing the guild's system channel
1244
+ * @returns {Promise<Guild>}
1245
+ * @example
1246
+ * // Edit the guild system channel
1247
+ * guild.setSystemChannel(channel)
1248
+ * .then(updated => console.log(`Updated guild system channel to ${guild.systemChannel.name}`))
1249
+ * .catch(console.error);
1250
+ */
1251
+ async setSystemChannel(systemChannel, reason) {
1252
+ return this.edit({ systemChannel, reason });
1253
+ }
1254
+
1255
+ /**
1256
+ * Edits the AFK timeout of the guild.
1257
+ *
1258
+ * @param {number} afkTimeout The time in seconds that a user must be idle to be considered AFK
1259
+ * @param {string} [reason] Reason for changing the guild's AFK timeout
1260
+ * @returns {Promise<Guild>}
1261
+ * @example
1262
+ * // Edit the guild AFK channel
1263
+ * guild.setAFKTimeout(60)
1264
+ * .then(updated => console.log(`Updated guild AFK timeout to ${guild.afkTimeout}`))
1265
+ * .catch(console.error);
1266
+ */
1267
+ async setAFKTimeout(afkTimeout, reason) {
1268
+ return this.edit({ afkTimeout, reason });
1269
+ }
1270
+
1271
+ /**
1272
+ * Sets a new guild icon.
1273
+ *
1274
+ * @param {?(Base64Resolvable|BufferResolvable)} icon The new icon of the guild
1275
+ * @param {string} [reason] Reason for changing the guild's icon
1276
+ * @returns {Promise<Guild>}
1277
+ * @example
1278
+ * // Edit the guild icon
1279
+ * guild.setIcon('./icon.png')
1280
+ * .then(updated => console.log('Updated the guild icon'))
1281
+ * .catch(console.error);
1282
+ */
1283
+ async setIcon(icon, reason) {
1284
+ return this.edit({ icon, reason });
1285
+ }
1286
+
1287
+ /**
1288
+ * Sets a new guild invite splash image.
1289
+ *
1290
+ * @param {?(Base64Resolvable|BufferResolvable)} splash The new invite splash image of the guild
1291
+ * @param {string} [reason] Reason for changing the guild's invite splash image
1292
+ * @returns {Promise<Guild>}
1293
+ * @example
1294
+ * // Edit the guild splash
1295
+ * guild.setSplash('./splash.png')
1296
+ * .then(updated => console.log('Updated the guild splash'))
1297
+ * .catch(console.error);
1298
+ */
1299
+ async setSplash(splash, reason) {
1300
+ return this.edit({ splash, reason });
1301
+ }
1302
+
1303
+ /**
1304
+ * Sets a new guild discovery splash image.
1305
+ *
1306
+ * @param {?(Base64Resolvable|BufferResolvable)} discoverySplash The new discovery splash image of the guild
1307
+ * @param {string} [reason] Reason for changing the guild's discovery splash image
1308
+ * @returns {Promise<Guild>}
1309
+ * @example
1310
+ * // Edit the guild discovery splash
1311
+ * guild.setDiscoverySplash('./discoverysplash.png')
1312
+ * .then(updated => console.log('Updated the guild discovery splash'))
1313
+ * .catch(console.error);
1314
+ */
1315
+ async setDiscoverySplash(discoverySplash, reason) {
1316
+ return this.edit({ discoverySplash, reason });
1317
+ }
1318
+
1319
+ /**
1320
+ * Sets a new guild banner.
1321
+ *
1322
+ * @param {?(Base64Resolvable|BufferResolvable)} banner The new banner of the guild
1323
+ * @param {string} [reason] Reason for changing the guild's banner
1324
+ * @returns {Promise<Guild>}
1325
+ * @example
1326
+ * guild.setBanner('./banner.png')
1327
+ * .then(updated => console.log('Updated the guild banner'))
1328
+ * .catch(console.error);
1329
+ */
1330
+ async setBanner(banner, reason) {
1331
+ return this.edit({ banner, reason });
1332
+ }
1333
+
1334
+ /**
1335
+ * Edits the rules channel of the guild.
1336
+ *
1337
+ * @param {?TextChannelResolvable} rulesChannel The new rules channel
1338
+ * @param {string} [reason] Reason for changing the guild's rules channel
1339
+ * @returns {Promise<Guild>}
1340
+ * @example
1341
+ * // Edit the guild rules channel
1342
+ * guild.setRulesChannel(channel)
1343
+ * .then(updated => console.log(`Updated guild rules channel to ${guild.rulesChannel.name}`))
1344
+ * .catch(console.error);
1345
+ */
1346
+ async setRulesChannel(rulesChannel, reason) {
1347
+ return this.edit({ rulesChannel, reason });
1348
+ }
1349
+
1350
+ /**
1351
+ * Edits the community updates channel of the guild.
1352
+ *
1353
+ * @param {?TextChannelResolvable} publicUpdatesChannel The new community updates channel
1354
+ * @param {string} [reason] Reason for changing the guild's community updates channel
1355
+ * @returns {Promise<Guild>}
1356
+ * @example
1357
+ * // Edit the guild community updates channel
1358
+ * guild.setPublicUpdatesChannel(channel)
1359
+ * .then(updated => console.log(`Updated guild community updates channel to ${guild.publicUpdatesChannel.name}`))
1360
+ * .catch(console.error);
1361
+ */
1362
+ async setPublicUpdatesChannel(publicUpdatesChannel, reason) {
1363
+ return this.edit({ publicUpdatesChannel, reason });
1364
+ }
1365
+
1366
+ /**
1367
+ * Edits the preferred locale of the guild.
1368
+ *
1369
+ * @param {?Locale} preferredLocale The new preferred locale of the guild
1370
+ * @param {string} [reason] Reason for changing the guild's preferred locale
1371
+ * @returns {Promise<Guild>}
1372
+ * @example
1373
+ * // Edit the guild preferred locale
1374
+ * guild.setPreferredLocale('en-US')
1375
+ * .then(updated => console.log(`Updated guild preferred locale to ${guild.preferredLocale}`))
1376
+ * .catch(console.error);
1377
+ */
1378
+ async setPreferredLocale(preferredLocale, reason) {
1379
+ return this.edit({ preferredLocale, reason });
1380
+ }
1381
+
1382
+ /**
1383
+ * Edits the enabled state of the guild's premium progress bar
1384
+ *
1385
+ * @param {boolean} [enabled=true] The new enabled state of the guild's premium progress bar
1386
+ * @param {string} [reason] Reason for changing the state of the guild's premium progress bar
1387
+ * @returns {Promise<Guild>}
1388
+ */
1389
+ async setPremiumProgressBarEnabled(enabled = true, reason = undefined) {
1390
+ return this.edit({ premiumProgressBarEnabled: enabled, reason });
1391
+ }
1392
+
1393
+ /**
1394
+ * Edits the safety alerts channel of the guild.
1395
+ *
1396
+ * @param {?TextChannelResolvable} safetyAlertsChannel The new safety alerts channel
1397
+ * @param {string} [reason] Reason for changing the guild's safety alerts channel
1398
+ * @returns {Promise<Guild>}
1399
+ * @example
1400
+ * // Edit the guild safety alerts channel
1401
+ * guild.setSafetyAlertsChannel(channel)
1402
+ * .then(updated => console.log(`Updated guild safety alerts channel to ${updated.safetyAlertsChannel.name}`))
1403
+ * .catch(console.error);
1404
+ */
1405
+ async setSafetyAlertsChannel(safetyAlertsChannel, reason) {
1406
+ return this.edit({ safetyAlertsChannel, reason });
1407
+ }
1408
+
1409
+ /**
1410
+ * Edits the guild's widget settings.
1411
+ *
1412
+ * @param {GuildWidgetSettingsData} settings The widget settings for the guild
1413
+ * @param {string} [reason] Reason for changing the guild's widget settings
1414
+ * @returns {Promise<Guild>}
1415
+ */
1416
+ async setWidgetSettings(settings, reason) {
1417
+ await this.client.rest.patch(Routes.guildWidgetSettings(this.id), {
1418
+ body: {
1419
+ enabled: settings.enabled,
1420
+ channel_id: this.channels.resolveId(settings.channel),
1421
+ },
1422
+ reason,
1423
+ });
1424
+ return this;
1425
+ }
1426
+
1427
+ /**
1428
+ * Leaves the guild.
1429
+ *
1430
+ * @returns {Promise<Guild>}
1431
+ * @example
1432
+ * // Leave a guild
1433
+ * guild.leave()
1434
+ * .then(guild => console.log(`Left the guild: ${guild.name}`))
1435
+ * .catch(console.error);
1436
+ */
1437
+ async leave() {
1438
+ await this.client.rest.delete(Routes.userGuild(this.id));
1439
+ return this;
1440
+ }
1441
+
1442
+ /**
1443
+ * Sets whether this guild's invites are disabled.
1444
+ *
1445
+ * @param {boolean} [disabled=true] Whether the invites are disabled
1446
+ * @returns {Promise<Guild>}
1447
+ */
1448
+ async disableInvites(disabled = true) {
1449
+ const features = this.features.filter(feature => feature !== GuildFeature.InvitesDisabled);
1450
+ if (disabled) features.push(GuildFeature.InvitesDisabled);
1451
+ return this.edit({ features });
1452
+ }
1453
+
1454
+ /**
1455
+ * Sets the incident actions for a guild.
1456
+ *
1457
+ * @param {IncidentActionsEditOptions} incidentActions The incident actions to set
1458
+ * @returns {Promise<IncidentActions>}
1459
+ */
1460
+ async setIncidentActions(incidentActions) {
1461
+ return this.client.guilds.setIncidentActions(this.id, incidentActions);
1462
+ }
1463
+
1464
+ /**
1465
+ * Whether this guild equals another guild. It compares all properties, so for most operations
1466
+ * it is advisable to just compare `guild.id === guild2.id` as it is much faster and is often
1467
+ * what most users need.
1468
+ *
1469
+ * @param {Guild} guild The guild to compare with
1470
+ * @returns {boolean}
1471
+ */
1472
+ equals(guild) {
1473
+ return (
1474
+ guild &&
1475
+ guild instanceof this.constructor &&
1476
+ this.id === guild.id &&
1477
+ this.available === guild.available &&
1478
+ this.splash === guild.splash &&
1479
+ this.discoverySplash === guild.discoverySplash &&
1480
+ this.name === guild.name &&
1481
+ this.memberCount === guild.memberCount &&
1482
+ this.large === guild.large &&
1483
+ this.icon === guild.icon &&
1484
+ this.ownerId === guild.ownerId &&
1485
+ this.verificationLevel === guild.verificationLevel &&
1486
+ (this.features === guild.features ||
1487
+ (this.features.length === guild.features.length &&
1488
+ this.features.every((feat, index) => feat === guild.features[index])))
1489
+ );
1490
+ }
1491
+
1492
+ toJSON() {
1493
+ const json = super.toJSON({
1494
+ available: false,
1495
+ createdTimestamp: true,
1496
+ nameAcronym: true,
1497
+ presences: false,
1498
+ voiceStates: false,
1499
+ });
1500
+ json.iconURL = this.iconURL();
1501
+ json.splashURL = this.splashURL();
1502
+ json.discoverySplashURL = this.discoverySplashURL();
1503
+ json.bannerURL = this.bannerURL();
1504
+ return json;
1505
+ }
1506
+
1507
+ /**
1508
+ * The voice state adapter for this guild that can be used with `@discordjs/voice` to play audio in voice
1509
+ * and stage channels.
1510
+ *
1511
+ * @type {Function}
1512
+ * @readonly
1513
+ */
1514
+ get voiceAdapterCreator() {
1515
+ return methods => {
1516
+ this.client.voice.adapters.set(this.id, methods);
1517
+ return {
1518
+ sendPayload: data => {
1519
+ this.client.ws.send(this.shardId, data);
1520
+ return true;
1521
+ },
1522
+ destroy: () => {
1523
+ this.client.voice.adapters.delete(this.id);
1524
+ },
1525
+ };
1526
+ };
1527
+ }
1528
+
1529
+ /**
1530
+ * Creates a collection of this guild's roles, sorted by their position and ids.
1531
+ *
1532
+ * @returns {Collection<Snowflake, Role>}
1533
+ * @private
1534
+ */
1535
+ _sortedRoles() {
1536
+ return discordSort(this.roles.cache);
1537
+ }
1538
+
1539
+ /**
1540
+ * Creates a collection of this guild's or a specific category's channels, sorted by their position and ids.
1541
+ *
1542
+ * @param {GuildChannel} [channel] Category to get the channels of
1543
+ * @returns {Collection<Snowflake, GuildChannel>}
1544
+ * @private
1545
+ */
1546
+ _sortedChannels(channel) {
1547
+ const channelIsCategory = channel.type === ChannelType.GuildCategory;
1548
+ const types = getSortableGroupTypes(channel.type);
1549
+ return discordSort(
1550
+ this.channels.cache.filter(
1551
+ ({ parentId, type }) => types.includes(type) && (channelIsCategory || parentId === channel.parentId),
1552
+ ),
1553
+ );
1554
+ }
1555
+ }
1556
+
1557
+ exports.Guild = Guild;