@velliajs/discord 1.0.0

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