discord.js-seflbot-v13 1.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of discord.js-seflbot-v13 might be problematic. Click here for more details.

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