safeness-sb-new 0.0.1

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