@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,494 @@
1
+ 'use strict';
2
+
3
+ const process = require('node:process');
4
+ const { Collection } = require('@discordjs/collection');
5
+ const { ChannelType, Routes } = require('discord-api-types/v10');
6
+ const CachedManager = require('./CachedManager');
7
+ const GuildTextThreadManager = require('./GuildTextThreadManager');
8
+ const { DiscordjsError, DiscordjsTypeError, ErrorCodes } = require('../errors');
9
+ const GuildChannel = require('../structures/GuildChannel');
10
+ const PermissionOverwrites = require('../structures/PermissionOverwrites');
11
+ const ThreadChannel = require('../structures/ThreadChannel');
12
+ const Webhook = require('../structures/Webhook');
13
+ const ChannelFlagsBitField = require('../util/ChannelFlagsBitField');
14
+ const { transformGuildForumTag, transformGuildDefaultReaction } = require('../util/Channels');
15
+ const { ThreadChannelTypes } = require('../util/Constants');
16
+ const DataResolver = require('../util/DataResolver');
17
+ const { setPosition } = require('../util/Util');
18
+
19
+ let cacheWarningEmitted = false;
20
+
21
+ /**
22
+ * Manages API methods for GuildChannels and stores their cache.
23
+ * @extends {CachedManager}
24
+ */
25
+ class GuildChannelManager extends CachedManager {
26
+ constructor(guild, iterable) {
27
+ super(guild.client, GuildChannel, iterable);
28
+ const defaultCaching =
29
+ this._cache.constructor.name === 'Collection' ||
30
+ this._cache.maxSize === undefined ||
31
+ this._cache.maxSize === Infinity;
32
+ if (!cacheWarningEmitted && !defaultCaching) {
33
+ cacheWarningEmitted = true;
34
+ process.emitWarning(
35
+ `Overriding the cache handling for ${this.constructor.name} is unsupported and breaks functionality.`,
36
+ 'UnsupportedCacheOverwriteWarning',
37
+ );
38
+ }
39
+
40
+ /**
41
+ * The guild this Manager belongs to
42
+ * @type {Guild}
43
+ */
44
+ this.guild = guild;
45
+ }
46
+
47
+ /**
48
+ * The number of channels in this managers cache excluding thread channels
49
+ * that do not count towards a guild's maximum channels restriction.
50
+ * @type {number}
51
+ * @readonly
52
+ */
53
+ get channelCountWithoutThreads() {
54
+ return this.cache.reduce((acc, channel) => {
55
+ if (ThreadChannelTypes.includes(channel.type)) return acc;
56
+ return ++acc;
57
+ }, 0);
58
+ }
59
+
60
+ /**
61
+ * The cache of this Manager
62
+ * @type {Collection<Snowflake, GuildChannel|ThreadChannel>}
63
+ * @name GuildChannelManager#cache
64
+ */
65
+
66
+ _add(channel) {
67
+ const existing = this.cache.get(channel.id);
68
+ if (existing) return existing;
69
+ this.cache.set(channel.id, channel);
70
+ return channel;
71
+ }
72
+
73
+ /**
74
+ * Data that can be resolved to give a Guild Channel object. This can be:
75
+ * * A GuildChannel object
76
+ * * A ThreadChannel object
77
+ * * A Snowflake
78
+ * @typedef {GuildChannel|ThreadChannel|Snowflake} GuildChannelResolvable
79
+ */
80
+
81
+ /**
82
+ * Resolves a GuildChannelResolvable to a Channel object.
83
+ * @param {GuildChannelResolvable} channel The GuildChannel resolvable to resolve
84
+ * @returns {?(GuildChannel|ThreadChannel)}
85
+ */
86
+ resolve(channel) {
87
+ if (channel instanceof ThreadChannel) return super.resolve(channel.id);
88
+ return super.resolve(channel);
89
+ }
90
+
91
+ /**
92
+ * Resolves a GuildChannelResolvable to a channel id.
93
+ * @param {GuildChannelResolvable} channel The GuildChannel resolvable to resolve
94
+ * @returns {?Snowflake}
95
+ */
96
+ resolveId(channel) {
97
+ if (channel instanceof ThreadChannel) return super.resolveId(channel.id);
98
+ return super.resolveId(channel);
99
+ }
100
+
101
+ /**
102
+ * Adds the target channel to a channel's followers.
103
+ * @param {NewsChannel|Snowflake} channel The channel to follow
104
+ * @param {TextChannelResolvable} targetChannel The channel where published announcements will be posted at
105
+ * @param {string} [reason] Reason for creating the webhook
106
+ * @returns {Promise<Snowflake>} Returns created target webhook id.
107
+ */
108
+ async addFollower(channel, targetChannel, reason) {
109
+ const channelId = this.resolveId(channel);
110
+ const targetChannelId = this.resolveId(targetChannel);
111
+ if (!channelId || !targetChannelId) throw new Error(ErrorCodes.GuildChannelResolve);
112
+ const { webhook_id } = await this.client.rest.post(Routes.channelFollowers(channelId), {
113
+ body: { webhook_channel_id: targetChannelId },
114
+ reason,
115
+ });
116
+ return webhook_id;
117
+ }
118
+
119
+ /**
120
+ * Options used to create a new channel in a guild.
121
+ * @typedef {CategoryCreateChannelOptions} GuildChannelCreateOptions
122
+ * @property {?CategoryChannelResolvable} [parent] Parent of the new channel
123
+ */
124
+
125
+ /**
126
+ * Creates a new channel in the guild.
127
+ * @param {GuildChannelCreateOptions} options Options for creating the new channel
128
+ * @returns {Promise<GuildChannel>}
129
+ * @example
130
+ * // Create a new text channel
131
+ * guild.channels.create({ name: 'new-general', reason: 'Needed a cool new channel' })
132
+ * .then(console.log)
133
+ * .catch(console.error);
134
+ * @example
135
+ * // Create a new channel with permission overwrites
136
+ * guild.channels.create({
137
+ * name: 'new-general',
138
+ * type: ChannelType.GuildVoice,
139
+ * permissionOverwrites: [
140
+ * {
141
+ * id: message.author.id,
142
+ * deny: [PermissionFlagsBits.ViewChannel],
143
+ * },
144
+ * ],
145
+ * })
146
+ */
147
+ async create({
148
+ name,
149
+ type,
150
+ topic,
151
+ nsfw,
152
+ bitrate,
153
+ userLimit,
154
+ parent,
155
+ permissionOverwrites,
156
+ position,
157
+ rateLimitPerUser,
158
+ rtcRegion,
159
+ videoQualityMode,
160
+ availableTags,
161
+ defaultReactionEmoji,
162
+ defaultAutoArchiveDuration,
163
+ defaultSortOrder,
164
+ defaultForumLayout,
165
+ reason,
166
+ }) {
167
+ parent &&= this.client.channels.resolveId(parent);
168
+ permissionOverwrites &&= permissionOverwrites.map(o => PermissionOverwrites.resolve(o, this.guild));
169
+
170
+ const data = await this.client.rest.post(Routes.guildChannels(this.guild.id), {
171
+ body: {
172
+ name,
173
+ topic,
174
+ type,
175
+ nsfw,
176
+ bitrate,
177
+ user_limit: userLimit,
178
+ parent_id: parent,
179
+ position,
180
+ permission_overwrites: permissionOverwrites,
181
+ rate_limit_per_user: rateLimitPerUser,
182
+ rtc_region: rtcRegion,
183
+ video_quality_mode: videoQualityMode,
184
+ available_tags: availableTags?.map(availableTag => transformGuildForumTag(availableTag)),
185
+ default_reaction_emoji: defaultReactionEmoji && transformGuildDefaultReaction(defaultReactionEmoji),
186
+ default_auto_archive_duration: defaultAutoArchiveDuration,
187
+ default_sort_order: defaultSortOrder,
188
+ default_forum_layout: defaultForumLayout,
189
+ },
190
+ reason,
191
+ });
192
+ return this.client.actions.ChannelCreate.handle(data).channel;
193
+ }
194
+
195
+ /**
196
+ * @typedef {ChannelWebhookCreateOptions} WebhookCreateOptions
197
+ * @property {TextChannel|NewsChannel|VoiceChannel|StageChannel|ForumChannel|Snowflake} channel
198
+ * The channel to create the webhook for
199
+ */
200
+
201
+ /**
202
+ * Creates a webhook for the channel.
203
+ * @param {WebhookCreateOptions} options Options for creating the webhook
204
+ * @returns {Promise<Webhook>} Returns the created Webhook
205
+ * @example
206
+ * // Create a webhook for the current channel
207
+ * guild.channels.createWebhook({
208
+ * channel: '222197033908436994',
209
+ * name: 'Snek',
210
+ * avatar: 'https://i.imgur.com/mI8XcpG.jpg',
211
+ * reason: 'Needed a cool new Webhook'
212
+ * })
213
+ * .then(console.log)
214
+ * .catch(console.error)
215
+ */
216
+ async createWebhook({ channel, name, avatar, reason }) {
217
+ const id = this.resolveId(channel);
218
+ if (!id) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'channel', 'GuildChannelResolvable');
219
+ if (typeof avatar === 'string' && !avatar.startsWith('data:')) {
220
+ avatar = await DataResolver.resolveImage(avatar);
221
+ }
222
+ const data = await this.client.rest.post(Routes.channelWebhooks(id), {
223
+ body: {
224
+ name,
225
+ avatar,
226
+ },
227
+ reason,
228
+ });
229
+ return new Webhook(this.client, data);
230
+ }
231
+
232
+ /**
233
+ * Options used to edit a guild channel.
234
+ * @typedef {Object} GuildChannelEditOptions
235
+ * @property {string} [name] The name of the channel
236
+ * @property {ChannelType} [type] The type of the channel (only conversion between text and news is supported)
237
+ * @property {number} [position] The position of the channel
238
+ * @property {?string} [topic] The topic of the text channel
239
+ * @property {boolean} [nsfw] Whether the channel is NSFW
240
+ * @property {number} [bitrate] The bitrate of the voice channel
241
+ * @property {number} [userLimit] The user limit of the voice channel
242
+ * @property {?CategoryChannelResolvable} [parent] The parent of the channel
243
+ * @property {boolean} [lockPermissions]
244
+ * Lock the permissions of the channel to what the parent's permissions are
245
+ * @property {OverwriteResolvable[]|Collection<Snowflake, OverwriteResolvable>} [permissionOverwrites]
246
+ * Permission overwrites for the channel
247
+ * @property {number} [rateLimitPerUser] The rate limit per user (slowmode) for the channel in seconds
248
+ * @property {ThreadAutoArchiveDuration} [defaultAutoArchiveDuration]
249
+ * The default auto archive duration for all new threads in this channel
250
+ * @property {?string} [rtcRegion] The RTC region of the channel
251
+ * @property {?VideoQualityMode} [videoQualityMode] The camera video quality mode of the channel
252
+ * @property {GuildForumTagData[]} [availableTags] The tags to set as available in a forum channel
253
+ * @property {?DefaultReactionEmoji} [defaultReactionEmoji] The emoji to set as the default reaction emoji
254
+ * @property {number} [defaultThreadRateLimitPerUser] The rate limit per user (slowmode) to set on forum posts
255
+ * @property {ChannelFlagsResolvable} [flags] The flags to set on the channel
256
+ * @property {?SortOrderType} [defaultSortOrder] The default sort order mode to set on the channel
257
+ * @property {ForumLayoutType} [defaultForumLayout] The default forum layout to set on the channel
258
+ * @property {string} [reason] Reason for editing this channel
259
+ */
260
+
261
+ /**
262
+ * Edits the channel.
263
+ * @param {GuildChannelResolvable} channel The channel to edit
264
+ * @param {GuildChannelEditOptions} options Options for editing the channel
265
+ * @returns {Promise<GuildChannel>}
266
+ * @example
267
+ * // Edit a channel
268
+ * guild.channels.edit('222197033908436994', { name: 'new-channel' })
269
+ * .then(console.log)
270
+ * .catch(console.error);
271
+ */
272
+ async edit(channel, options) {
273
+ channel = this.resolve(channel);
274
+ if (!channel) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'channel', 'GuildChannelResolvable');
275
+
276
+ const parent = options.parent && this.client.channels.resolveId(options.parent);
277
+
278
+ if (options.position !== undefined) {
279
+ await this.setPosition(channel, options.position, { position: options.position, reason: options.reason });
280
+ }
281
+
282
+ let permission_overwrites = options.permissionOverwrites?.map(o => PermissionOverwrites.resolve(o, this.guild));
283
+
284
+ if (options.lockPermissions) {
285
+ if (parent) {
286
+ const newParent = this.guild.channels.resolve(parent);
287
+ if (newParent?.type === ChannelType.GuildCategory) {
288
+ permission_overwrites = newParent.permissionOverwrites.cache.map(o =>
289
+ PermissionOverwrites.resolve(o, this.guild),
290
+ );
291
+ }
292
+ } else if (channel.parent) {
293
+ permission_overwrites = channel.parent.permissionOverwrites.cache.map(o =>
294
+ PermissionOverwrites.resolve(o, this.guild),
295
+ );
296
+ }
297
+ }
298
+
299
+ const newData = await this.client.rest.patch(Routes.channel(channel.id), {
300
+ body: {
301
+ name: (options.name ?? channel.name).trim(),
302
+ type: options.type,
303
+ topic: options.topic,
304
+ nsfw: options.nsfw,
305
+ bitrate: options.bitrate ?? channel.bitrate,
306
+ user_limit: options.userLimit ?? channel.userLimit,
307
+ rtc_region: 'rtcRegion' in options ? options.rtcRegion : channel.rtcRegion,
308
+ video_quality_mode: options.videoQualityMode,
309
+ parent_id: parent,
310
+ lock_permissions: options.lockPermissions,
311
+ rate_limit_per_user: options.rateLimitPerUser,
312
+ default_auto_archive_duration: options.defaultAutoArchiveDuration,
313
+ permission_overwrites,
314
+ available_tags: options.availableTags?.map(availableTag => transformGuildForumTag(availableTag)),
315
+ default_reaction_emoji:
316
+ options.defaultReactionEmoji && transformGuildDefaultReaction(options.defaultReactionEmoji),
317
+ default_thread_rate_limit_per_user: options.defaultThreadRateLimitPerUser,
318
+ flags: 'flags' in options ? ChannelFlagsBitField.resolve(options.flags) : undefined,
319
+ default_sort_order: options.defaultSortOrder,
320
+ default_forum_layout: options.defaultForumLayout,
321
+ },
322
+ reason: options.reason,
323
+ });
324
+
325
+ return this.client.actions.ChannelUpdate.handle(newData).updated;
326
+ }
327
+
328
+ /**
329
+ * Sets a new position for the guild channel.
330
+ * @param {GuildChannelResolvable} channel The channel to set the position for
331
+ * @param {number} position The new position for the guild channel
332
+ * @param {SetChannelPositionOptions} options Options for setting position
333
+ * @returns {Promise<GuildChannel>}
334
+ * @example
335
+ * // Set a new channel position
336
+ * guild.channels.setPosition('222078374472843266', 2)
337
+ * .then(newChannel => console.log(`Channel's new position is ${newChannel.position}`))
338
+ * .catch(console.error);
339
+ */
340
+ async setPosition(channel, position, { relative, reason } = {}) {
341
+ channel = this.resolve(channel);
342
+ if (!channel) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'channel', 'GuildChannelResolvable');
343
+ const updatedChannels = await setPosition(
344
+ channel,
345
+ position,
346
+ relative,
347
+ this.guild._sortedChannels(channel),
348
+ this.client,
349
+ Routes.guildChannels(this.guild.id),
350
+ reason,
351
+ );
352
+
353
+ this.client.actions.GuildChannelsPositionUpdate.handle({
354
+ guild_id: this.guild.id,
355
+ channels: updatedChannels,
356
+ });
357
+ return channel;
358
+ }
359
+
360
+ /**
361
+ * Obtains one or more guild channels from Discord, or the channel cache if they're already available.
362
+ * @param {Snowflake} [id] The channel's id
363
+ * @param {BaseFetchOptions} [options] Additional options for this fetch
364
+ * @returns {Promise<?GuildChannel|ThreadChannel|Collection<Snowflake, ?GuildChannel>>}
365
+ * @example
366
+ * // Fetch all channels from the guild (excluding threads)
367
+ * message.guild.channels.fetch()
368
+ * .then(channels => console.log(`There are ${channels.size} channels.`))
369
+ * .catch(console.error);
370
+ * @example
371
+ * // Fetch a single channel
372
+ * message.guild.channels.fetch('222197033908436994')
373
+ * .then(channel => console.log(`The channel name is: ${channel.name}`))
374
+ * .catch(console.error);
375
+ */
376
+ async fetch(id, { cache = true, force = false } = {}) {
377
+ if (id && !force) {
378
+ const existing = this.cache.get(id);
379
+ if (existing) return existing;
380
+ }
381
+
382
+ if (id) {
383
+ const data = await this.client.rest.get(Routes.channel(id));
384
+ // Since this is the guild manager, throw if on a different guild
385
+ if (this.guild.id !== data.guild_id) throw new DiscordjsError(ErrorCodes.GuildChannelUnowned);
386
+ return this.client.channels._add(data, this.guild, { cache });
387
+ }
388
+
389
+ const data = await this.client.rest.get(Routes.guildChannels(this.guild.id));
390
+ const channels = new Collection();
391
+ for (const channel of data) channels.set(channel.id, this.client.channels._add(channel, this.guild, { cache }));
392
+ return channels;
393
+ }
394
+
395
+ /**
396
+ * Fetches all webhooks for the channel.
397
+ * @param {GuildChannelResolvable} channel The channel to fetch webhooks for
398
+ * @returns {Promise<Collection<Snowflake, Webhook>>}
399
+ * @example
400
+ * // Fetch webhooks
401
+ * guild.channels.fetchWebhooks('769862166131245066')
402
+ * .then(hooks => console.log(`This channel has ${hooks.size} hooks`))
403
+ * .catch(console.error);
404
+ */
405
+ async fetchWebhooks(channel) {
406
+ const id = this.resolveId(channel);
407
+ if (!id) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'channel', 'GuildChannelResolvable');
408
+ const data = await this.client.rest.get(Routes.channelWebhooks(id));
409
+ return data.reduce((hooks, hook) => hooks.set(hook.id, new Webhook(this.client, hook)), new Collection());
410
+ }
411
+
412
+ /**
413
+ * Data that can be resolved to give a Category Channel object. This can be:
414
+ * * A CategoryChannel object
415
+ * * A Snowflake
416
+ * @typedef {CategoryChannel|Snowflake} CategoryChannelResolvable
417
+ */
418
+
419
+ /**
420
+ * The data needed for updating a channel's position.
421
+ * @typedef {Object} ChannelPosition
422
+ * @property {GuildChannel|Snowflake} channel Channel to update
423
+ * @property {number} [position] New position for the channel
424
+ * @property {CategoryChannelResolvable} [parent] Parent channel for this channel
425
+ * @property {boolean} [lockPermissions] If the overwrites should be locked to the parents overwrites
426
+ */
427
+
428
+ /**
429
+ * Batch-updates the guild's channels' positions.
430
+ * <info>Only one channel's parent can be changed at a time</info>
431
+ * @param {ChannelPosition[]} channelPositions Channel positions to update
432
+ * @returns {Promise<Guild>}
433
+ * @example
434
+ * guild.channels.setPositions([{ channel: channelId, position: newChannelIndex }])
435
+ * .then(guild => console.log(`Updated channel positions for ${guild}`))
436
+ * .catch(console.error);
437
+ */
438
+ async setPositions(channelPositions) {
439
+ channelPositions = channelPositions.map(r => ({
440
+ id: this.client.channels.resolveId(r.channel),
441
+ position: r.position,
442
+ lock_permissions: r.lockPermissions,
443
+ parent_id: r.parent !== undefined ? this.resolveId(r.parent) : undefined,
444
+ }));
445
+
446
+ await this.client.rest.patch(Routes.guildChannels(this.guild.id), { body: channelPositions });
447
+ return this.client.actions.GuildChannelsPositionUpdate.handle({
448
+ guild_id: this.guild.id,
449
+ channels: channelPositions,
450
+ }).guild;
451
+ }
452
+
453
+ /**
454
+ * Data returned from fetching threads.
455
+ * @typedef {Object} FetchedThreads
456
+ * @property {Collection<Snowflake, ThreadChannel>} threads The threads that were fetched
457
+ * @property {Collection<Snowflake, ThreadMember>} members The thread members in the received threads
458
+ */
459
+
460
+ /**
461
+ * Obtains all active thread channels in the guild.
462
+ * @param {boolean} [cache=true] Whether to cache the fetched data
463
+ * @returns {Promise<FetchedThreads>}
464
+ * @example
465
+ * // Fetch all threads from the guild
466
+ * message.guild.channels.fetchActiveThreads()
467
+ * .then(fetched => console.log(`There are ${fetched.threads.size} threads.`))
468
+ * .catch(console.error);
469
+ */
470
+ async fetchActiveThreads(cache = true) {
471
+ const raw = await this.client.rest.get(Routes.guildActiveThreads(this.guild.id));
472
+ return GuildTextThreadManager._mapThreads(raw, this.client, { guild: this.guild, cache });
473
+ }
474
+
475
+ /**
476
+ * Deletes the channel.
477
+ * @param {GuildChannelResolvable} channel The channel to delete
478
+ * @param {string} [reason] Reason for deleting this channel
479
+ * @returns {Promise<void>}
480
+ * @example
481
+ * // Delete the channel
482
+ * guild.channels.delete('858850993013260338', 'making room for new channels')
483
+ * .then(console.log)
484
+ * .catch(console.error);
485
+ */
486
+ async delete(channel, reason) {
487
+ const id = this.resolveId(channel);
488
+ if (!id) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'channel', 'GuildChannelResolvable');
489
+ await this.client.rest.delete(Routes.channel(id), { reason });
490
+ this.client.actions.ChannelDelete.handle({ id });
491
+ }
492
+ }
493
+
494
+ module.exports = GuildChannelManager;
@@ -0,0 +1,174 @@
1
+ 'use strict';
2
+
3
+ const { Collection } = require('@discordjs/collection');
4
+ const { Routes, PermissionFlagsBits } = require('discord-api-types/v10');
5
+ const BaseGuildEmojiManager = require('./BaseGuildEmojiManager');
6
+ const { DiscordjsError, DiscordjsTypeError, ErrorCodes } = require('../errors');
7
+ const DataResolver = require('../util/DataResolver');
8
+
9
+ /**
10
+ * Manages API methods for GuildEmojis and stores their cache.
11
+ * @extends {BaseGuildEmojiManager}
12
+ */
13
+ class GuildEmojiManager extends BaseGuildEmojiManager {
14
+ constructor(guild, iterable) {
15
+ super(guild.client, iterable);
16
+
17
+ /**
18
+ * The guild this manager belongs to
19
+ * @type {Guild}
20
+ */
21
+ this.guild = guild;
22
+ }
23
+
24
+ _add(data, cache) {
25
+ return super._add(data, cache, { extras: [this.guild] });
26
+ }
27
+
28
+ /**
29
+ * Options used for creating an emoji in a guild.
30
+ * @typedef {Object} GuildEmojiCreateOptions
31
+ * @property {BufferResolvable|Base64Resolvable} attachment The image for the emoji
32
+ * @property {string} name The name for the emoji
33
+ * @property {Collection<Snowflake, Role>|RoleResolvable[]} [roles] The roles to limit the emoji to
34
+ * @property {string} [reason] The reason for creating the emoji
35
+ */
36
+
37
+ /**
38
+ * Creates a new custom emoji in the guild.
39
+ * @param {GuildEmojiCreateOptions} options Options for creating the emoji
40
+ * @returns {Promise<Emoji>} The created emoji
41
+ * @example
42
+ * // Create a new emoji from a URL
43
+ * guild.emojis.create({ attachment: 'https://i.imgur.com/w3duR07.png', name: 'rip' })
44
+ * .then(emoji => console.log(`Created new emoji with name ${emoji.name}!`))
45
+ * .catch(console.error);
46
+ * @example
47
+ * // Create a new emoji from a file on your computer
48
+ * guild.emojis.create({ attachment: './memes/banana.png', name: 'banana' })
49
+ * .then(emoji => console.log(`Created new emoji with name ${emoji.name}!`))
50
+ * .catch(console.error);
51
+ */
52
+ async create({ attachment, name, roles, reason }) {
53
+ attachment = await DataResolver.resolveImage(attachment);
54
+ if (!attachment) throw new DiscordjsTypeError(ErrorCodes.ReqResourceType);
55
+
56
+ const body = { image: attachment, name };
57
+ if (roles) {
58
+ if (!Array.isArray(roles) && !(roles instanceof Collection)) {
59
+ throw new DiscordjsTypeError(
60
+ ErrorCodes.InvalidType,
61
+ 'options.roles',
62
+ 'Array or Collection of Roles or Snowflakes',
63
+ true,
64
+ );
65
+ }
66
+ body.roles = [];
67
+ for (const role of roles.values()) {
68
+ const resolvedRole = this.guild.roles.resolveId(role);
69
+ if (!resolvedRole) {
70
+ throw new DiscordjsTypeError(ErrorCodes.InvalidElement, 'Array or Collection', 'options.roles', role);
71
+ }
72
+ body.roles.push(resolvedRole);
73
+ }
74
+ }
75
+
76
+ const emoji = await this.client.rest.post(Routes.guildEmojis(this.guild.id), { body, reason });
77
+ return this.client.actions.GuildEmojiCreate.handle(this.guild, emoji).emoji;
78
+ }
79
+
80
+ /**
81
+ * Obtains one or more emojis from Discord, or the emoji cache if they're already available.
82
+ * @param {Snowflake} [id] The emoji's id
83
+ * @param {BaseFetchOptions} [options] Additional options for this fetch
84
+ * @returns {Promise<GuildEmoji|Collection<Snowflake, GuildEmoji>>}
85
+ * @example
86
+ * // Fetch all emojis from the guild
87
+ * message.guild.emojis.fetch()
88
+ * .then(emojis => console.log(`There are ${emojis.size} emojis.`))
89
+ * .catch(console.error);
90
+ * @example
91
+ * // Fetch a single emoji
92
+ * message.guild.emojis.fetch('222078108977594368')
93
+ * .then(emoji => console.log(`The emoji name is: ${emoji.name}`))
94
+ * .catch(console.error);
95
+ */
96
+ async fetch(id, { cache = true, force = false } = {}) {
97
+ if (id) {
98
+ if (!force) {
99
+ const existing = this.cache.get(id);
100
+ if (existing) return existing;
101
+ }
102
+ const emoji = await this.client.rest.get(Routes.guildEmoji(this.guild.id, id));
103
+ return this._add(emoji, cache);
104
+ }
105
+
106
+ const data = await this.client.rest.get(Routes.guildEmojis(this.guild.id));
107
+ const emojis = new Collection();
108
+ for (const emoji of data) emojis.set(emoji.id, this._add(emoji, cache));
109
+ return emojis;
110
+ }
111
+
112
+ /**
113
+ * Deletes an emoji.
114
+ * @param {EmojiResolvable} emoji The Emoji resolvable to delete
115
+ * @param {string} [reason] Reason for deleting the emoji
116
+ * @returns {Promise<void>}
117
+ */
118
+ async delete(emoji, reason) {
119
+ const id = this.resolveId(emoji);
120
+ if (!id) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'emoji', 'EmojiResolvable', true);
121
+ await this.client.rest.delete(Routes.guildEmoji(this.guild.id, id), { reason });
122
+ }
123
+
124
+ /**
125
+ * Edits an emoji.
126
+ * @param {EmojiResolvable} emoji The Emoji resolvable to edit
127
+ * @param {GuildEmojiEditOptions} options The options to provide
128
+ * @returns {Promise<GuildEmoji>}
129
+ */
130
+ async edit(emoji, options) {
131
+ const id = this.resolveId(emoji);
132
+ if (!id) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'emoji', 'EmojiResolvable', true);
133
+ const roles = options.roles?.map(r => this.guild.roles.resolveId(r));
134
+ const newData = await this.client.rest.patch(Routes.guildEmoji(this.guild.id, id), {
135
+ body: {
136
+ name: options.name,
137
+ roles,
138
+ },
139
+ reason: options.reason,
140
+ });
141
+ const existing = this.cache.get(id);
142
+ if (existing) {
143
+ const clone = existing._clone();
144
+ clone._patch(newData);
145
+ return clone;
146
+ }
147
+ return this._add(newData);
148
+ }
149
+
150
+ /**
151
+ * Fetches the author for this emoji
152
+ * @param {EmojiResolvable} emoji The emoji to fetch the author of
153
+ * @returns {Promise<User>}
154
+ */
155
+ async fetchAuthor(emoji) {
156
+ emoji = this.resolve(emoji);
157
+ if (!emoji) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'emoji', 'EmojiResolvable', true);
158
+ if (emoji.managed) {
159
+ throw new DiscordjsError(ErrorCodes.EmojiManaged);
160
+ }
161
+
162
+ const { me } = this.guild.members;
163
+ if (!me) throw new DiscordjsError(ErrorCodes.GuildUncachedMe);
164
+ if (!me.permissions.has(PermissionFlagsBits.ManageGuildExpressions)) {
165
+ throw new DiscordjsError(ErrorCodes.MissingManageGuildExpressionsPermission, this.guild);
166
+ }
167
+
168
+ const data = await this.client.rest.get(Routes.guildEmoji(this.guild.id, emoji.id));
169
+ emoji._patch(data);
170
+ return emoji.author;
171
+ }
172
+ }
173
+
174
+ module.exports = GuildEmojiManager;