lolka.js 0.1.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 (337) hide show
  1. package/LICENSE +191 -0
  2. package/README.md +148 -0
  3. package/package.json +104 -0
  4. package/src/client/Client.js +943 -0
  5. package/src/client/actions/Action.js +151 -0
  6. package/src/client/actions/ActionsManager.js +75 -0
  7. package/src/client/actions/ChannelCreate.js +25 -0
  8. package/src/client/actions/ChannelDelete.js +24 -0
  9. package/src/client/actions/ChannelUpdate.js +42 -0
  10. package/src/client/actions/GuildChannelsPositionUpdate.js +21 -0
  11. package/src/client/actions/GuildEmojiCreate.js +21 -0
  12. package/src/client/actions/GuildEmojiDelete.js +20 -0
  13. package/src/client/actions/GuildEmojiUpdate.js +21 -0
  14. package/src/client/actions/GuildEmojisUpdate.js +34 -0
  15. package/src/client/actions/GuildMemberRemove.js +33 -0
  16. package/src/client/actions/GuildMemberUpdate.js +45 -0
  17. package/src/client/actions/GuildRoleCreate.js +27 -0
  18. package/src/client/actions/GuildRoleDelete.js +30 -0
  19. package/src/client/actions/GuildRolesPositionUpdate.js +21 -0
  20. package/src/client/actions/GuildScheduledEventDelete.js +32 -0
  21. package/src/client/actions/GuildScheduledEventUserAdd.js +33 -0
  22. package/src/client/actions/GuildScheduledEventUserRemove.js +33 -0
  23. package/src/client/actions/GuildSoundboardSoundDelete.js +30 -0
  24. package/src/client/actions/GuildStickerCreate.js +21 -0
  25. package/src/client/actions/GuildStickerDelete.js +20 -0
  26. package/src/client/actions/GuildStickerUpdate.js +21 -0
  27. package/src/client/actions/GuildStickersUpdate.js +34 -0
  28. package/src/client/actions/GuildUpdate.js +34 -0
  29. package/src/client/actions/InteractionCreate.js +110 -0
  30. package/src/client/actions/MessageCreate.js +43 -0
  31. package/src/client/actions/MessageDelete.js +33 -0
  32. package/src/client/actions/MessageDeleteBulk.js +49 -0
  33. package/src/client/actions/MessagePollVoteAdd.js +41 -0
  34. package/src/client/actions/MessagePollVoteRemove.js +39 -0
  35. package/src/client/actions/MessageReactionAdd.js +72 -0
  36. package/src/client/actions/MessageReactionRemove.js +51 -0
  37. package/src/client/actions/MessageReactionRemoveAll.js +34 -0
  38. package/src/client/actions/MessageReactionRemoveEmoji.js +29 -0
  39. package/src/client/actions/MessageUpdate.js +26 -0
  40. package/src/client/actions/StageInstanceCreate.js +29 -0
  41. package/src/client/actions/StageInstanceDelete.js +32 -0
  42. package/src/client/actions/StageInstanceUpdate.js +31 -0
  43. package/src/client/actions/ThreadCreate.js +26 -0
  44. package/src/client/actions/ThreadMembersUpdate.js +49 -0
  45. package/src/client/actions/TypingStart.js +30 -0
  46. package/src/client/actions/UserUpdate.js +37 -0
  47. package/src/client/voice/ClientVoiceManager.js +48 -0
  48. package/src/client/websocket/handlers/APPLICATION_COMMAND_PERMISSIONS_UPDATE.js +30 -0
  49. package/src/client/websocket/handlers/AUTO_MODERATION_ACTION_EXECUTION.js +18 -0
  50. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_CREATE.js +19 -0
  51. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_DELETE.js +22 -0
  52. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_UPDATE.js +21 -0
  53. package/src/client/websocket/handlers/CHANNEL_CREATE.js +5 -0
  54. package/src/client/websocket/handlers/CHANNEL_DELETE.js +5 -0
  55. package/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.js +23 -0
  56. package/src/client/websocket/handlers/CHANNEL_UPDATE.js +17 -0
  57. package/src/client/websocket/handlers/ENTITLEMENT_CREATE.js +15 -0
  58. package/src/client/websocket/handlers/ENTITLEMENT_DELETE.js +19 -0
  59. package/src/client/websocket/handlers/ENTITLEMENT_UPDATE.js +17 -0
  60. package/src/client/websocket/handlers/GUILD_AUDIT_LOG_ENTRY_CREATE.js +20 -0
  61. package/src/client/websocket/handlers/GUILD_BAN_ADD.js +16 -0
  62. package/src/client/websocket/handlers/GUILD_BAN_REMOVE.js +21 -0
  63. package/src/client/websocket/handlers/GUILD_CREATE.js +35 -0
  64. package/src/client/websocket/handlers/GUILD_DELETE.js +37 -0
  65. package/src/client/websocket/handlers/GUILD_EMOJIS_UPDATE.js +5 -0
  66. package/src/client/websocket/handlers/GUILD_INTEGRATIONS_UPDATE.js +16 -0
  67. package/src/client/websocket/handlers/GUILD_MEMBERS_CHUNK.js +41 -0
  68. package/src/client/websocket/handlers/GUILD_MEMBER_ADD.js +18 -0
  69. package/src/client/websocket/handlers/GUILD_MEMBER_REMOVE.js +5 -0
  70. package/src/client/websocket/handlers/GUILD_MEMBER_UPDATE.js +5 -0
  71. package/src/client/websocket/handlers/GUILD_ROLE_CREATE.js +5 -0
  72. package/src/client/websocket/handlers/GUILD_ROLE_DELETE.js +5 -0
  73. package/src/client/websocket/handlers/GUILD_ROLE_UPDATE.js +22 -0
  74. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_CREATE.js +18 -0
  75. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_DELETE.js +5 -0
  76. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_UPDATE.js +20 -0
  77. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_ADD.js +5 -0
  78. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_REMOVE.js +5 -0
  79. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUNDS_UPDATE.js +25 -0
  80. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_CREATE.js +19 -0
  81. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_DELETE.js +5 -0
  82. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_UPDATE.js +21 -0
  83. package/src/client/websocket/handlers/GUILD_STICKERS_UPDATE.js +5 -0
  84. package/src/client/websocket/handlers/GUILD_UPDATE.js +5 -0
  85. package/src/client/websocket/handlers/INTERACTION_CREATE.js +5 -0
  86. package/src/client/websocket/handlers/INVITE_CREATE.js +21 -0
  87. package/src/client/websocket/handlers/INVITE_DELETE.js +24 -0
  88. package/src/client/websocket/handlers/MESSAGE_CREATE.js +5 -0
  89. package/src/client/websocket/handlers/MESSAGE_DELETE.js +5 -0
  90. package/src/client/websocket/handlers/MESSAGE_DELETE_BULK.js +5 -0
  91. package/src/client/websocket/handlers/MESSAGE_POLL_VOTE_ADD.js +5 -0
  92. package/src/client/websocket/handlers/MESSAGE_POLL_VOTE_REMOVE.js +5 -0
  93. package/src/client/websocket/handlers/MESSAGE_REACTION_ADD.js +5 -0
  94. package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE.js +5 -0
  95. package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_ALL.js +5 -0
  96. package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_EMOJI.js +5 -0
  97. package/src/client/websocket/handlers/MESSAGE_UPDATE.js +17 -0
  98. package/src/client/websocket/handlers/PRESENCE_UPDATE.js +43 -0
  99. package/src/client/websocket/handlers/RATE_LIMITED.js +24 -0
  100. package/src/client/websocket/handlers/READY.js +30 -0
  101. package/src/client/websocket/handlers/SOUNDBOARD_SOUNDS.js +25 -0
  102. package/src/client/websocket/handlers/STAGE_INSTANCE_CREATE.js +5 -0
  103. package/src/client/websocket/handlers/STAGE_INSTANCE_DELETE.js +5 -0
  104. package/src/client/websocket/handlers/STAGE_INSTANCE_UPDATE.js +5 -0
  105. package/src/client/websocket/handlers/SUBSCRIPTION_CREATE.js +15 -0
  106. package/src/client/websocket/handlers/SUBSCRIPTION_DELETE.js +17 -0
  107. package/src/client/websocket/handlers/SUBSCRIPTION_UPDATE.js +17 -0
  108. package/src/client/websocket/handlers/THREAD_CREATE.js +5 -0
  109. package/src/client/websocket/handlers/THREAD_DELETE.js +18 -0
  110. package/src/client/websocket/handlers/THREAD_LIST_SYNC.js +52 -0
  111. package/src/client/websocket/handlers/THREAD_MEMBERS_UPDATE.js +5 -0
  112. package/src/client/websocket/handlers/THREAD_MEMBER_UPDATE.js +26 -0
  113. package/src/client/websocket/handlers/THREAD_UPDATE.js +17 -0
  114. package/src/client/websocket/handlers/TYPING_START.js +5 -0
  115. package/src/client/websocket/handlers/USER_UPDATE.js +5 -0
  116. package/src/client/websocket/handlers/VOICE_CHANNEL_EFFECT_SEND.js +17 -0
  117. package/src/client/websocket/handlers/VOICE_SERVER_UPDATE.js +33 -0
  118. package/src/client/websocket/handlers/VOICE_STATE_UPDATE.js +38 -0
  119. package/src/client/websocket/handlers/WEBHOOKS_UPDATE.js +17 -0
  120. package/src/client/websocket/handlers/index.js +78 -0
  121. package/src/errors/DJSError.js +52 -0
  122. package/src/errors/ErrorCodes.js +280 -0
  123. package/src/errors/Messages.js +159 -0
  124. package/src/errors/index.js +7 -0
  125. package/src/index.js +261 -0
  126. package/src/managers/ApplicationCommandManager.js +305 -0
  127. package/src/managers/ApplicationCommandPermissionsManager.js +452 -0
  128. package/src/managers/ApplicationEmojiManager.js +152 -0
  129. package/src/managers/AutoModerationRuleManager.js +310 -0
  130. package/src/managers/BaseManager.js +21 -0
  131. package/src/managers/CachedManager.js +68 -0
  132. package/src/managers/CategoryChannelChildManager.js +85 -0
  133. package/src/managers/ChannelManager.js +197 -0
  134. package/src/managers/DMMessageManager.js +19 -0
  135. package/src/managers/DataManager.js +66 -0
  136. package/src/managers/EntitlementManager.js +185 -0
  137. package/src/managers/GuildApplicationCommandManager.js +31 -0
  138. package/src/managers/GuildBanManager.js +224 -0
  139. package/src/managers/GuildChannelManager.js +556 -0
  140. package/src/managers/GuildEmojiManager.js +264 -0
  141. package/src/managers/GuildEmojiRoleManager.js +136 -0
  142. package/src/managers/GuildForumThreadManager.js +88 -0
  143. package/src/managers/GuildInviteManager.js +239 -0
  144. package/src/managers/GuildManager.js +268 -0
  145. package/src/managers/GuildMemberManager.js +622 -0
  146. package/src/managers/GuildMemberRoleManager.js +232 -0
  147. package/src/managers/GuildMessageManager.js +35 -0
  148. package/src/managers/GuildScheduledEventManager.js +333 -0
  149. package/src/managers/GuildSoundboardSoundManager.js +226 -0
  150. package/src/managers/GuildStickerManager.js +195 -0
  151. package/src/managers/GuildTextThreadManager.js +95 -0
  152. package/src/managers/MessageManager.js +355 -0
  153. package/src/managers/PartialGroupDMMessageManager.js +19 -0
  154. package/src/managers/PermissionOverwriteManager.js +177 -0
  155. package/src/managers/PollAnswerVoterManager.js +62 -0
  156. package/src/managers/PresenceManager.js +63 -0
  157. package/src/managers/ReactionManager.js +75 -0
  158. package/src/managers/ReactionUserManager.js +85 -0
  159. package/src/managers/RoleManager.js +446 -0
  160. package/src/managers/StageInstanceManager.js +169 -0
  161. package/src/managers/SubscriptionManager.js +86 -0
  162. package/src/managers/ThreadManager.js +213 -0
  163. package/src/managers/ThreadMemberManager.js +197 -0
  164. package/src/managers/UserManager.js +149 -0
  165. package/src/managers/VoiceStateManager.js +64 -0
  166. package/src/sharding/Shard.js +506 -0
  167. package/src/sharding/ShardClientUtil.js +292 -0
  168. package/src/sharding/ShardingManager.js +390 -0
  169. package/src/structures/ActionRow.js +34 -0
  170. package/src/structures/ActivityInstance.js +52 -0
  171. package/src/structures/ActivityLocation.js +65 -0
  172. package/src/structures/AnnouncementChannel.js +29 -0
  173. package/src/structures/AnonymousGuild.js +107 -0
  174. package/src/structures/ApplicationCommand.js +657 -0
  175. package/src/structures/ApplicationEmoji.js +186 -0
  176. package/src/structures/ApplicationRoleConnectionMetadata.js +52 -0
  177. package/src/structures/Attachment.js +181 -0
  178. package/src/structures/AuthorizingIntegrationOwners.js +64 -0
  179. package/src/structures/AutoModerationActionExecution.js +131 -0
  180. package/src/structures/AutoModerationRule.js +317 -0
  181. package/src/structures/AutocompleteInteraction.js +112 -0
  182. package/src/structures/Base.js +45 -0
  183. package/src/structures/BaseChannel.js +188 -0
  184. package/src/structures/BaseGuild.js +134 -0
  185. package/src/structures/BaseGuildEmoji.js +111 -0
  186. package/src/structures/BaseGuildTextChannel.js +225 -0
  187. package/src/structures/BaseGuildVoiceChannel.js +265 -0
  188. package/src/structures/BaseInteraction.js +378 -0
  189. package/src/structures/BaseInvite.js +187 -0
  190. package/src/structures/BaseSelectMenuComponent.js +62 -0
  191. package/src/structures/ButtonComponent.js +72 -0
  192. package/src/structures/ButtonInteraction.js +12 -0
  193. package/src/structures/CategoryChannel.js +50 -0
  194. package/src/structures/ChannelSelectMenuComponent.js +22 -0
  195. package/src/structures/ChannelSelectMenuInteraction.js +36 -0
  196. package/src/structures/ChatInputCommandInteraction.js +45 -0
  197. package/src/structures/ClientApplication.js +463 -0
  198. package/src/structures/ClientPresence.js +89 -0
  199. package/src/structures/ClientUser.js +221 -0
  200. package/src/structures/CommandInteraction.js +188 -0
  201. package/src/structures/CommandInteractionOptionResolver.js +336 -0
  202. package/src/structures/Component.js +62 -0
  203. package/src/structures/ContainerComponent.js +66 -0
  204. package/src/structures/ContextMenuCommandInteraction.js +69 -0
  205. package/src/structures/DMChannel.js +162 -0
  206. package/src/structures/DirectoryChannel.js +40 -0
  207. package/src/structures/Embed.js +254 -0
  208. package/src/structures/Emoji.js +115 -0
  209. package/src/structures/Entitlement.js +199 -0
  210. package/src/structures/FileComponent.js +44 -0
  211. package/src/structures/ForumChannel.js +34 -0
  212. package/src/structures/GroupDMInvite.js +37 -0
  213. package/src/structures/Guild.js +1557 -0
  214. package/src/structures/GuildAuditLogs.js +97 -0
  215. package/src/structures/GuildAuditLogsEntry.js +552 -0
  216. package/src/structures/GuildBan.js +65 -0
  217. package/src/structures/GuildChannel.js +511 -0
  218. package/src/structures/GuildEmoji.js +160 -0
  219. package/src/structures/GuildInvite.js +223 -0
  220. package/src/structures/GuildMember.js +650 -0
  221. package/src/structures/GuildOnboarding.js +71 -0
  222. package/src/structures/GuildOnboardingPrompt.js +88 -0
  223. package/src/structures/GuildOnboardingPromptOption.js +96 -0
  224. package/src/structures/GuildPreview.js +213 -0
  225. package/src/structures/GuildPreviewEmoji.js +30 -0
  226. package/src/structures/GuildScheduledEvent.js +579 -0
  227. package/src/structures/GuildTemplate.js +221 -0
  228. package/src/structures/Integration.js +243 -0
  229. package/src/structures/IntegrationApplication.js +82 -0
  230. package/src/structures/InteractionCallback.js +83 -0
  231. package/src/structures/InteractionCallbackResource.js +57 -0
  232. package/src/structures/InteractionCallbackResponse.js +36 -0
  233. package/src/structures/InteractionCollector.js +256 -0
  234. package/src/structures/InteractionWebhook.js +67 -0
  235. package/src/structures/InviteGuild.js +24 -0
  236. package/src/structures/LabelComponent.js +54 -0
  237. package/src/structures/MediaChannel.js +12 -0
  238. package/src/structures/MediaGalleryComponent.js +34 -0
  239. package/src/structures/MediaGalleryItem.js +56 -0
  240. package/src/structures/MentionableSelectMenuComponent.js +12 -0
  241. package/src/structures/MentionableSelectMenuInteraction.js +76 -0
  242. package/src/structures/Message.js +1203 -0
  243. package/src/structures/MessageCollector.js +157 -0
  244. package/src/structures/MessageComponentInteraction.js +128 -0
  245. package/src/structures/MessageContextMenuCommandInteraction.js +22 -0
  246. package/src/structures/MessageMentions.js +323 -0
  247. package/src/structures/MessagePayload.js +346 -0
  248. package/src/structures/MessageReaction.js +214 -0
  249. package/src/structures/ModalComponentResolver.js +269 -0
  250. package/src/structures/ModalSubmitInteraction.js +274 -0
  251. package/src/structures/OAuth2Guild.js +31 -0
  252. package/src/structures/PartialGroupDMChannel.js +146 -0
  253. package/src/structures/PermissionOverwrites.js +221 -0
  254. package/src/structures/Poll.js +190 -0
  255. package/src/structures/PollAnswer.js +98 -0
  256. package/src/structures/Presence.js +429 -0
  257. package/src/structures/PrimaryEntryPointCommandInteraction.js +12 -0
  258. package/src/structures/ReactionCollector.js +246 -0
  259. package/src/structures/ReactionEmoji.js +33 -0
  260. package/src/structures/Role.js +539 -0
  261. package/src/structures/RoleSelectMenuComponent.js +12 -0
  262. package/src/structures/RoleSelectMenuInteraction.js +36 -0
  263. package/src/structures/SKU.js +59 -0
  264. package/src/structures/SectionComponent.js +46 -0
  265. package/src/structures/SeparatorComponent.js +33 -0
  266. package/src/structures/SoundboardSound.js +220 -0
  267. package/src/structures/StageChannel.js +121 -0
  268. package/src/structures/StageInstance.js +170 -0
  269. package/src/structures/Sticker.js +292 -0
  270. package/src/structures/StickerPack.js +107 -0
  271. package/src/structures/StringSelectMenuComponent.js +22 -0
  272. package/src/structures/StringSelectMenuInteraction.js +23 -0
  273. package/src/structures/Subscription.js +131 -0
  274. package/src/structures/Team.js +129 -0
  275. package/src/structures/TeamMember.js +77 -0
  276. package/src/structures/TextChannel.js +36 -0
  277. package/src/structures/TextDisplayComponent.js +22 -0
  278. package/src/structures/TextInputComponent.js +32 -0
  279. package/src/structures/ThreadChannel.js +662 -0
  280. package/src/structures/ThreadMember.js +124 -0
  281. package/src/structures/ThreadOnlyChannel.js +270 -0
  282. package/src/structures/ThumbnailComponent.js +54 -0
  283. package/src/structures/Typing.js +82 -0
  284. package/src/structures/UnfurledMediaItem.js +36 -0
  285. package/src/structures/User.js +505 -0
  286. package/src/structures/UserContextMenuCommandInteraction.js +32 -0
  287. package/src/structures/UserSelectMenuComponent.js +12 -0
  288. package/src/structures/UserSelectMenuInteraction.js +55 -0
  289. package/src/structures/VoiceChannel.js +123 -0
  290. package/src/structures/VoiceChannelEffect.js +88 -0
  291. package/src/structures/VoiceRegion.js +51 -0
  292. package/src/structures/VoiceState.js +338 -0
  293. package/src/structures/Webhook.js +520 -0
  294. package/src/structures/WelcomeChannel.js +67 -0
  295. package/src/structures/WelcomeScreen.js +54 -0
  296. package/src/structures/Widget.js +107 -0
  297. package/src/structures/WidgetMember.js +114 -0
  298. package/src/structures/interfaces/Application.js +173 -0
  299. package/src/structures/interfaces/Collector.js +368 -0
  300. package/src/structures/interfaces/InteractionResponses.js +385 -0
  301. package/src/structures/interfaces/TextBasedChannel.js +431 -0
  302. package/src/util/APITypes.js +700 -0
  303. package/src/util/ActivityFlagsBitField.js +29 -0
  304. package/src/util/ApplicationFlagsBitField.js +46 -0
  305. package/src/util/AttachmentFlagsBitField.js +29 -0
  306. package/src/util/BitField.js +197 -0
  307. package/src/util/ChannelFlagsBitField.js +46 -0
  308. package/src/util/Channels.js +173 -0
  309. package/src/util/Colors.js +73 -0
  310. package/src/util/Components.js +329 -0
  311. package/src/util/Constants.js +253 -0
  312. package/src/util/DataResolver.js +161 -0
  313. package/src/util/Enums.js +14 -0
  314. package/src/util/Events.js +179 -0
  315. package/src/util/GuildMemberFlagsBitField.js +46 -0
  316. package/src/util/IntentsBitField.js +38 -0
  317. package/src/util/InviteFlagsBitField.js +29 -0
  318. package/src/util/Invites.js +31 -0
  319. package/src/util/LimitedCollection.js +75 -0
  320. package/src/util/LolkaSnowflake.js +47 -0
  321. package/src/util/MessageFlagsBitField.js +46 -0
  322. package/src/util/Options.js +221 -0
  323. package/src/util/Partials.js +51 -0
  324. package/src/util/PermissionsBitField.js +117 -0
  325. package/src/util/RoleFlagsBitField.js +29 -0
  326. package/src/util/SKUFlagsBitField.js +29 -0
  327. package/src/util/ShardEvents.js +27 -0
  328. package/src/util/Status.js +17 -0
  329. package/src/util/Sweepers.js +533 -0
  330. package/src/util/Symbols.js +3 -0
  331. package/src/util/SystemChannelFlagsBitField.js +48 -0
  332. package/src/util/ThreadMemberFlagsBitField.js +36 -0
  333. package/src/util/Transformers.js +124 -0
  334. package/src/util/UserFlagsBitField.js +36 -0
  335. package/src/util/Util.js +609 -0
  336. package/typings/index.d.mts +7512 -0
  337. package/typings/index.d.ts +7512 -0
@@ -0,0 +1,452 @@
1
+ 'use strict';
2
+
3
+ const { Collection } = require('@discordjs/collection');
4
+ const { ApplicationCommandPermissionType, RESTJSONErrorCodes, Routes } = require('discord-api-types/v10');
5
+ const { DiscordjsError, DiscordjsTypeError, ErrorCodes } = require('../errors/index.js');
6
+ const { BaseManager } = require('./BaseManager.js');
7
+
8
+ /**
9
+ * Manages API methods for permissions of Application Commands.
10
+ *
11
+ * @extends {BaseManager}
12
+ */
13
+ class ApplicationCommandPermissionsManager extends BaseManager {
14
+ constructor(manager) {
15
+ super(manager.client);
16
+
17
+ /**
18
+ * The manager or command that this manager belongs to
19
+ *
20
+ * @type {ApplicationCommandManager|ApplicationCommand}
21
+ * @private
22
+ */
23
+ this.manager = manager;
24
+
25
+ /**
26
+ * The guild that this manager acts on
27
+ *
28
+ * @type {?Guild}
29
+ */
30
+ this.guild = manager.guild ?? null;
31
+
32
+ /**
33
+ * The id of the guild that this manager acts on
34
+ *
35
+ * @type {?Snowflake}
36
+ */
37
+ this.guildId = manager.guildId ?? manager.guild?.id ?? null;
38
+
39
+ /**
40
+ * The id of the command this manager acts on
41
+ *
42
+ * @type {?Snowflake}
43
+ */
44
+ this.commandId = manager.id ?? null;
45
+ }
46
+
47
+ /**
48
+ * The APIRouter path to the commands
49
+ *
50
+ * @param {Snowflake} guildId The guild's id to use in the path,
51
+ * @param {Snowflake} [commandId] The application command's id
52
+ * @returns {string}
53
+ * @private
54
+ */
55
+ permissionsPath(guildId, commandId) {
56
+ if (commandId) {
57
+ return Routes.applicationCommandPermissions(this.client.application.id, guildId, commandId);
58
+ }
59
+
60
+ return Routes.guildApplicationCommandsPermissions(this.client.application.id, guildId);
61
+ }
62
+
63
+ /**
64
+ * The object returned when fetching permissions for an application command.
65
+ *
66
+ * @typedef {Object} ApplicationCommandPermissions
67
+ * @property {Snowflake} id The role, user, or channel's id. Can also be a
68
+ * {@link https://discord.com/developers/docs/interactions/application-commands#application-command-permissions-object-application-command-permissions-constants permission constant}.
69
+ * @property {ApplicationCommandPermissionType} type Whether this permission is for a role or a user
70
+ * @property {boolean} permission Whether the role or user has the permission to use this command
71
+ */
72
+
73
+ /**
74
+ * Options for managing permissions for one or more Application Commands
75
+ * <warn>When passing these options to a manager where `guildId` is `null`,
76
+ * `guild` is a required parameter</warn>
77
+ *
78
+ * @typedef {Object} BaseApplicationCommandPermissionsOptions
79
+ * @property {GuildResolvable} [guild] The guild to modify / check permissions for
80
+ * <warn>Ignored when the manager has a non-null `guildId` property</warn>
81
+ * @property {ApplicationCommandResolvable} [command] The command to modify / check permissions for
82
+ * <warn>Ignored when the manager has a non-null `commandId` property</warn>
83
+ */
84
+
85
+ /**
86
+ * Fetches the permissions for one or multiple commands. Providing the client's id as the "command id" will fetch
87
+ * _only_ the guild level permissions
88
+ *
89
+ * @param {BaseApplicationCommandPermissionsOptions} [options] Options used to fetch permissions
90
+ * @returns {Promise<ApplicationCommandPermissions[]|Collection<Snowflake, ApplicationCommandPermissions[]>>}
91
+ * @example
92
+ * // Fetch permissions for one command
93
+ * guild.commands.permissions.fetch({ command: '123456789012345678' })
94
+ * .then(perms => console.log(`Fetched ${perms.length} overwrites`))
95
+ * .catch(console.error);
96
+ * @example
97
+ * // Fetch permissions for all commands in a guild
98
+ * client.application.commands.permissions.fetch({ guild: '123456789012345678' })
99
+ * .then(perms => console.log(`Fetched permissions for ${perms.size} commands`))
100
+ * .catch(console.error);
101
+ * @example
102
+ * // Fetch guild level permissions
103
+ * guild.commands.permissions.fetch({ command: client.user.id })
104
+ * .then(perms => console.log(`Fetched ${perms.length} guild level permissions`))
105
+ * .catch(console.error);
106
+ */
107
+ async fetch({ guild, command } = {}) {
108
+ const { guildId, commandId } = this._validateOptions(guild, command);
109
+ if (commandId) {
110
+ const innerData = await this.client.rest.get(this.permissionsPath(guildId, commandId));
111
+ return innerData.permissions;
112
+ }
113
+
114
+ const data = await this.client.rest.get(this.permissionsPath(guildId));
115
+ return data.reduce((coll, perm) => coll.set(perm.id, perm.permissions), new Collection());
116
+ }
117
+
118
+ /**
119
+ * Options used to set permissions for one or more Application Commands in a guild
120
+ * <warn>Omitting the `command` parameter edits the guild wide permissions
121
+ * when the manager's `commandId` is `null`</warn>
122
+ *
123
+ * @typedef {BaseApplicationCommandPermissionsOptions} ApplicationCommandPermissionsEditOptions
124
+ * @property {ApplicationCommandPermissions[]} permissions The new permissions for the guild or overwrite
125
+ * @property {string} token The bearer token to use that authorizes the permission edit
126
+ */
127
+
128
+ /**
129
+ * Sets the permissions for the guild or a command overwrite.
130
+ *
131
+ * @param {ApplicationCommandPermissionsEditOptions} options Options used to set permissions
132
+ * @returns {Promise<ApplicationCommandPermissions[]|Collection<Snowflake, ApplicationCommandPermissions[]>>}
133
+ * @example
134
+ * // Set a permission overwrite for a command
135
+ * client.application.commands.permissions.set({
136
+ * guild: '892455839386304532',
137
+ * command: '123456789012345678',
138
+ * token: 'TotallyRealToken',
139
+ * permissions: [
140
+ * {
141
+ * id: '876543210987654321',
142
+ * type: ApplicationCommandPermissionType.User,
143
+ * permission: false,
144
+ * },
145
+ * ]})
146
+ * .then(console.log)
147
+ * .catch(console.error);
148
+ * @example
149
+ * // Set the permissions used for the guild (commands without overwrites)
150
+ * guild.commands.permissions.set({ token: 'TotallyRealToken', permissions: [
151
+ * {
152
+ * id: '123456789012345678',
153
+ * permissions: [{
154
+ * id: '876543210987654321',
155
+ * type: ApplicationCommandPermissionType.User,
156
+ * permission: false,
157
+ * }],
158
+ * },
159
+ * ]})
160
+ * .then(console.log)
161
+ * .catch(console.error);
162
+ */
163
+ async set({ guild, command, permissions, token } = {}) {
164
+ if (!token) {
165
+ throw new DiscordjsError(ErrorCodes.ApplicationCommandPermissionsTokenMissing);
166
+ }
167
+
168
+ const options = this._validateOptions(guild, command);
169
+ let { commandId } = options;
170
+
171
+ if (!Array.isArray(permissions)) {
172
+ throw new DiscordjsTypeError(
173
+ ErrorCodes.InvalidType,
174
+ 'permissions',
175
+ 'Array of ApplicationCommandPermissions',
176
+ true,
177
+ );
178
+ }
179
+
180
+ commandId ??= this.client.user.id;
181
+
182
+ const data = await this.client.rest.put(this.permissionsPath(options.guildId, commandId), {
183
+ body: { permissions },
184
+ auth: false,
185
+ headers: { Authorization: `Bearer ${token}` },
186
+ });
187
+ return data.permissions;
188
+ }
189
+
190
+ /**
191
+ * Add permissions to a command.
192
+ *
193
+ * @param {ApplicationCommandPermissionsEditOptions} options Options used to add permissions
194
+ * @returns {Promise<ApplicationCommandPermissions[]>}
195
+ * @example
196
+ * // Add a rule to block a role from using a command
197
+ * guild.commands.permissions.add({ command: '123456789012345678', token: 'TotallyRealToken', permissions: [
198
+ * {
199
+ * id: '876543211234567890',
200
+ * type: ApplicationCommandPermissionType.Role,
201
+ * permission: false
202
+ * },
203
+ * ]})
204
+ * .then(console.log)
205
+ * .catch(console.error);
206
+ */
207
+ async add({ guild, command, permissions, token } = {}) {
208
+ if (!token) {
209
+ throw new DiscordjsError(ErrorCodes.ApplicationCommandPermissionsTokenMissing);
210
+ }
211
+
212
+ const options = this._validateOptions(guild, command);
213
+ let { commandId } = options;
214
+ commandId ??= this.client.user.id;
215
+
216
+ if (!Array.isArray(permissions)) {
217
+ throw new DiscordjsTypeError(
218
+ ErrorCodes.InvalidType,
219
+ 'permissions',
220
+ 'Array of ApplicationCommandPermissions',
221
+ true,
222
+ );
223
+ }
224
+
225
+ let existingPermissions = [];
226
+ try {
227
+ existingPermissions = await this.fetch({ guild: options.guildId, command: commandId });
228
+ } catch (error) {
229
+ if (error.code !== RESTJSONErrorCodes.UnknownApplicationCommandPermissions) throw error;
230
+ }
231
+
232
+ const newPermissions = permissions.slice();
233
+ for (const existingPermission of existingPermissions) {
234
+ if (!newPermissions.some(newPermission => newPermission.id === existingPermission.id)) {
235
+ newPermissions.push(existingPermission);
236
+ }
237
+ }
238
+
239
+ return this.set({ guild: options.guildId, command: commandId, permissions: newPermissions, token });
240
+ }
241
+
242
+ /**
243
+ * A static snowflake that identifies the everyone role for application command permissions.
244
+ * It is the same as the guild id
245
+ *
246
+ * @typedef {Snowflake} RolePermissionConstant
247
+ */
248
+
249
+ /**
250
+ * A static snowflake that identifies the "all channels" entity for application command permissions.
251
+ * It will be the result of the calculation `guildId - 1`
252
+ *
253
+ * @typedef {Snowflake} ChannelPermissionConstant
254
+ */
255
+
256
+ /**
257
+ * Options used to remove permissions from a command
258
+ * <warn>Omitting the `command` parameter removes from the guild wide permissions
259
+ * when the managers `commandId` is `null`</warn>
260
+ * <warn>At least one of `users`, `roles`, and `channels` is required</warn>
261
+ *
262
+ * @typedef {BaseApplicationCommandPermissionsOptions} RemoveApplicationCommandPermissionsOptions
263
+ * @property {string} token The bearer token to use that authorizes the permission removal
264
+ * @property {UserResolvable[]} [users] The user(s) to remove
265
+ * @property {Array<RoleResolvable|RolePermissionConstant>} [roles] The role(s) to remove
266
+ * @property {Array<GuildChannelResolvable|ChannelPermissionConstant>} [channels] The channel(s) to remove
267
+ */
268
+
269
+ /**
270
+ * Remove permissions from a command.
271
+ *
272
+ * @param {RemoveApplicationCommandPermissionsOptions} options Options used to remove permissions
273
+ * @returns {Promise<ApplicationCommandPermissions[]>}
274
+ * @example
275
+ * // Remove a user permission from this command
276
+ * guild.commands.permissions.remove({
277
+ * command: '123456789012345678', users: '876543210123456789', token: 'TotallyRealToken',
278
+ * })
279
+ * .then(console.log)
280
+ * .catch(console.error);
281
+ * @example
282
+ * // Remove multiple roles from this command
283
+ * guild.commands.permissions.remove({
284
+ * command: '123456789012345678', roles: ['876543210123456789', '765432101234567890'], token: 'TotallyRealToken',
285
+ * })
286
+ * .then(console.log)
287
+ * .catch(console.error);
288
+ */
289
+ async remove({ guild, command, users, roles, channels, token } = {}) {
290
+ if (!token) {
291
+ throw new DiscordjsError(ErrorCodes.ApplicationCommandPermissionsTokenMissing);
292
+ }
293
+
294
+ const options = this._validateOptions(guild, command);
295
+ let { commandId } = options;
296
+ commandId ??= this.client.user.id;
297
+
298
+ if (!users && !roles && !channels) {
299
+ throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'users OR roles OR channels', 'Array or Resolvable', true);
300
+ }
301
+
302
+ const resolvedUserIds = [];
303
+ if (Array.isArray(users)) {
304
+ for (const user of users) {
305
+ const userId = this.client.users.resolveId(user);
306
+ if (!userId) throw new DiscordjsTypeError(ErrorCodes.InvalidElement, 'Array', 'users', user);
307
+ resolvedUserIds.push(userId);
308
+ }
309
+ }
310
+
311
+ const resolvedRoleIds = [];
312
+ if (Array.isArray(roles)) {
313
+ for (const role of roles) {
314
+ if (typeof role === 'string') {
315
+ resolvedRoleIds.push(role);
316
+ continue;
317
+ }
318
+
319
+ if (!this.guild) throw new DiscordjsError(ErrorCodes.GuildUncachedEntityResolve, 'roles');
320
+ const roleId = this.guild.roles.resolveId(role);
321
+ if (!roleId) throw new DiscordjsTypeError(ErrorCodes.InvalidElement, 'Array', 'users', role);
322
+ resolvedRoleIds.push(roleId);
323
+ }
324
+ }
325
+
326
+ const resolvedChannelIds = [];
327
+ if (Array.isArray(channels)) {
328
+ for (const channel of channels) {
329
+ if (typeof channel === 'string') {
330
+ resolvedChannelIds.push(channel);
331
+ continue;
332
+ }
333
+
334
+ if (!this.guild) throw new DiscordjsError(ErrorCodes.GuildUncachedEntityResolve, 'channels');
335
+ const channelId = this.guild.channels.resolveId(channel);
336
+ if (!channelId) throw new DiscordjsTypeError(ErrorCodes.InvalidElement, 'Array', 'channels', channel);
337
+ resolvedChannelIds.push(channelId);
338
+ }
339
+ }
340
+
341
+ let existing = [];
342
+ try {
343
+ existing = await this.fetch({ guild: options.guildId, command: commandId });
344
+ } catch (error) {
345
+ if (error.code !== RESTJSONErrorCodes.UnknownApplicationCommandPermissions) throw error;
346
+ }
347
+
348
+ const permissions = existing.filter(perm => {
349
+ switch (perm.type) {
350
+ case ApplicationCommandPermissionType.Role:
351
+ return !resolvedRoleIds.includes(perm.id);
352
+ case ApplicationCommandPermissionType.User:
353
+ return !resolvedUserIds.includes(perm.id);
354
+ case ApplicationCommandPermissionType.Channel:
355
+ return !resolvedChannelIds.includes(perm.id);
356
+ default:
357
+ return true;
358
+ }
359
+ });
360
+
361
+ return this.set({ guild: options.guildId, command: commandId, permissions, token });
362
+ }
363
+
364
+ /**
365
+ * Options used to check the existence of permissions on a command
366
+ * <warn>The `command` parameter is not optional when the managers `commandId` is `null`</warn>
367
+ *
368
+ * @typedef {BaseApplicationCommandPermissionsOptions} HasApplicationCommandPermissionsOptions
369
+ * @property {ApplicationCommandPermissionIdResolvable} permissionId The entity to check if a permission exists for
370
+ * on this command.
371
+ * @property {ApplicationCommandPermissionType} [permissionType] Check for a specific type of permission
372
+ */
373
+
374
+ /**
375
+ * Check whether a permission exists for a user, role, or channel
376
+ *
377
+ * @param {HasApplicationCommandPermissionsOptions} options Options used to check permissions
378
+ * @returns {Promise<boolean>}
379
+ * @example
380
+ * guild.commands.permissions.has({ command: '123456789012345678', permissionId: '876543210123456789' })
381
+ * .then(console.log)
382
+ * .catch(console.error);
383
+ */
384
+ async has({ guild, command, permissionId, permissionType }) {
385
+ const { guildId, commandId } = this._validateOptions(guild, command);
386
+ if (!commandId) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'command', 'ApplicationCommandResolvable');
387
+
388
+ if (!permissionId) {
389
+ throw new DiscordjsTypeError(
390
+ ErrorCodes.InvalidType,
391
+ 'permissionId',
392
+ 'UserResolvable, RoleResolvable, ChannelResolvable, or Permission Constant',
393
+ );
394
+ }
395
+
396
+ let resolvedId = permissionId;
397
+ if (typeof permissionId !== 'string') {
398
+ resolvedId = this.client.users.resolveId(permissionId);
399
+ if (!resolvedId) {
400
+ if (!this.guild) throw new DiscordjsError(ErrorCodes.GuildUncachedEntityResolve, 'roles');
401
+ resolvedId = this.guild.roles.resolveId(permissionId);
402
+ }
403
+
404
+ resolvedId ??= this.guild.channels.resolveId(permissionId);
405
+
406
+ if (!resolvedId) {
407
+ throw new DiscordjsTypeError(
408
+ ErrorCodes.InvalidType,
409
+ 'permissionId',
410
+ 'UserResolvable, RoleResolvable, ChannelResolvable, or Permission Constant',
411
+ );
412
+ }
413
+ }
414
+
415
+ let existing = [];
416
+ try {
417
+ existing = await this.fetch({ guild: guildId, command: commandId });
418
+ } catch (error) {
419
+ if (error.code !== RESTJSONErrorCodes.UnknownApplicationCommandPermissions) throw error;
420
+ }
421
+
422
+ // Check permission type if provided for the single edge case where a channel id is the same as the everyone role id
423
+ return existing.some(perm => perm.id === resolvedId && (permissionType ?? perm.type) === perm.type);
424
+ }
425
+
426
+ _validateOptions(guild, command) {
427
+ const guildId = this.guildId ?? this.client.guilds.resolveId(guild);
428
+ if (!guildId) throw new DiscordjsError(ErrorCodes.GlobalCommandPermissions);
429
+ let commandId = this.commandId;
430
+ if (command && !commandId) {
431
+ commandId = this.manager.resolveId?.(command);
432
+ if (!commandId && this.guild) {
433
+ commandId = this.guild.commands.resolveId(command);
434
+ }
435
+
436
+ commandId ??= this.client.application?.commands.resolveId(command);
437
+ if (!commandId) {
438
+ throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'command', 'ApplicationCommandResolvable', true);
439
+ }
440
+ }
441
+
442
+ return { guildId, commandId };
443
+ }
444
+ }
445
+
446
+ exports.ApplicationCommandPermissionsManager = ApplicationCommandPermissionsManager;
447
+
448
+ /**
449
+ * Data that resolves to an id used for an application command permission
450
+ *
451
+ * @typedef {UserResolvable|RoleResolvable|GuildChannelResolvable|RolePermissionConstant|ChannelPermissionConstant} ApplicationCommandPermissionIdResolvable
452
+ */
@@ -0,0 +1,152 @@
1
+ 'use strict';
2
+
3
+ const { Collection } = require('@discordjs/collection');
4
+ const { Routes } = require('discord-api-types/v10');
5
+ const { DiscordjsTypeError, ErrorCodes } = require('../errors/index.js');
6
+ const { ApplicationEmoji } = require('../structures/ApplicationEmoji.js');
7
+ const { resolveImage } = require('../util/DataResolver.js');
8
+ const { CachedManager } = require('./CachedManager.js');
9
+
10
+ /**
11
+ * Manages API methods for ApplicationEmojis and stores their cache.
12
+ *
13
+ * @extends {CachedManager}
14
+ */
15
+ class ApplicationEmojiManager extends CachedManager {
16
+ constructor(application, iterable) {
17
+ super(application.client, ApplicationEmoji, iterable);
18
+
19
+ /**
20
+ * The application this manager belongs to
21
+ *
22
+ * @type {ClientApplication}
23
+ */
24
+ this.application = application;
25
+ }
26
+
27
+ _add(data, cache) {
28
+ return super._add(data, cache, { extras: [this.application] });
29
+ }
30
+
31
+ /**
32
+ * Options used for creating an emoji of the application
33
+ *
34
+ * @typedef {Object} ApplicationEmojiCreateOptions
35
+ * @property {BufferResolvable|Base64Resolvable} attachment The image for the emoji
36
+ * @property {string} name The name for the emoji
37
+ */
38
+
39
+ /**
40
+ * Creates a new custom emoji of the application.
41
+ *
42
+ * @param {ApplicationEmojiCreateOptions} options Options for creating the emoji
43
+ * @returns {Promise<Emoji>} The created emoji
44
+ * @example
45
+ * // Create a new emoji from a URL
46
+ * application.emojis.create({ attachment: 'https://i.imgur.com/w3duR07.png', name: 'rip' })
47
+ * .then(emoji => console.log(`Created new emoji with name ${emoji.name}!`))
48
+ * .catch(console.error);
49
+ * @example
50
+ * // Create a new emoji from a file on your computer
51
+ * application.emojis.create({ attachment: './memes/banana.png', name: 'banana' })
52
+ * .then(emoji => console.log(`Created new emoji with name ${emoji.name}!`))
53
+ * .catch(console.error);
54
+ */
55
+ async create({ attachment, name }) {
56
+ const image = await resolveImage(attachment);
57
+ if (!image) throw new DiscordjsTypeError(ErrorCodes.ReqResourceType);
58
+
59
+ const body = { image, name };
60
+
61
+ const emoji = await this.client.rest.post(Routes.applicationEmojis(this.application.id), { body });
62
+ return this._add(emoji);
63
+ }
64
+
65
+ /**
66
+ * Obtains one or more emojis from Discord, or the emoji cache if they're already available.
67
+ *
68
+ * @param {Snowflake} [id] The emoji's id
69
+ * @param {BaseFetchOptions} [options] Additional options for this fetch
70
+ * @returns {Promise<ApplicationEmoji|Collection<Snowflake, ApplicationEmoji>>}
71
+ * @example
72
+ * // Fetch all emojis from the application
73
+ * application.emojis.fetch()
74
+ * .then(emojis => console.log(`There are ${emojis.size} emojis.`))
75
+ * .catch(console.error);
76
+ * @example
77
+ * // Fetch a single emoji
78
+ * application.emojis.fetch('222078108977594368')
79
+ * .then(emoji => console.log(`The emoji name is: ${emoji.name}`))
80
+ * .catch(console.error);
81
+ */
82
+ async fetch(id, { cache = true, force = false } = {}) {
83
+ if (id) {
84
+ if (!force) {
85
+ const existing = this.cache.get(id);
86
+ if (existing) return existing;
87
+ }
88
+
89
+ const emoji = await this.client.rest.get(Routes.applicationEmoji(this.application.id, id));
90
+ return this._add(emoji, cache);
91
+ }
92
+
93
+ const { items: data } = await this.client.rest.get(Routes.applicationEmojis(this.application.id));
94
+ const emojis = new Collection();
95
+ for (const emoji of data) emojis.set(emoji.id, this._add(emoji, cache));
96
+ return emojis;
97
+ }
98
+
99
+ /**
100
+ * Deletes an emoji.
101
+ *
102
+ * @param {EmojiResolvable} emoji The Emoji resolvable to delete
103
+ * @returns {Promise<void>}
104
+ */
105
+ async delete(emoji) {
106
+ const id = this.resolveId(emoji);
107
+ if (!id) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'emoji', 'EmojiResolvable', true);
108
+ await this.client.rest.delete(Routes.applicationEmoji(this.application.id, id));
109
+ }
110
+
111
+ /**
112
+ * Edits an emoji.
113
+ *
114
+ * @param {EmojiResolvable} emoji The Emoji resolvable to edit
115
+ * @param {ApplicationEmojiEditOptions} options The options to provide
116
+ * @returns {Promise<ApplicationEmoji>}
117
+ */
118
+ async edit(emoji, options) {
119
+ const id = this.resolveId(emoji);
120
+ if (!id) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'emoji', 'EmojiResolvable', true);
121
+
122
+ const newData = await this.client.rest.patch(Routes.applicationEmoji(this.application.id, id), {
123
+ body: {
124
+ name: options.name,
125
+ },
126
+ });
127
+ const existing = this.cache.get(id);
128
+ if (existing) {
129
+ existing._patch(newData);
130
+ return existing;
131
+ }
132
+
133
+ return this._add(newData);
134
+ }
135
+
136
+ /**
137
+ * Fetches the author for this emoji
138
+ *
139
+ * @param {EmojiResolvable} emoji The emoji to fetch the author of
140
+ * @returns {Promise<User>}
141
+ */
142
+ async fetchAuthor(emoji) {
143
+ const id = this.resolveId(emoji);
144
+ if (!id) throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'emoji', 'EmojiResolvable', true);
145
+
146
+ const data = await this.client.rest.get(Routes.applicationEmoji(this.application.id, id));
147
+
148
+ return this._add(data).author;
149
+ }
150
+ }
151
+
152
+ exports.ApplicationEmojiManager = ApplicationEmojiManager;