@ovencord/discord.js 14.16.3

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