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,1203 @@
1
+ 'use strict';
2
+
3
+ const { Collection } = require('@discordjs/collection');
4
+ const { messageLink } = require('@discordjs/formatters');
5
+ const { DiscordSnowflake } = require('../util/LolkaSnowflake');
6
+ const {
7
+ InteractionType,
8
+ ChannelType,
9
+ MessageType,
10
+ MessageFlags,
11
+ MessageReferenceType,
12
+ PermissionFlagsBits,
13
+ } = require('discord-api-types/v10');
14
+ const { DiscordjsError, ErrorCodes } = require('../errors/index.js');
15
+ const { ReactionManager } = require('../managers/ReactionManager.js');
16
+ const { createComponent, findComponentByCustomId } = require('../util/Components.js');
17
+ const { NonSystemMessageTypes, MaxBulkDeletableMessageAge, UndeletableMessageTypes } = require('../util/Constants.js');
18
+ const { MessageFlagsBitField } = require('../util/MessageFlagsBitField.js');
19
+ const { PermissionsBitField } = require('../util/PermissionsBitField.js');
20
+ const { _transformAPIMessageInteractionMetadata } = require('../util/Transformers.js');
21
+ const { cleanContent, resolvePartialEmoji, transformResolved } = require('../util/Util.js');
22
+ const { Attachment } = require('./Attachment.js');
23
+ const { Base } = require('./Base.js');
24
+ const { ClientApplication } = require('./ClientApplication.js');
25
+ const { Embed } = require('./Embed.js');
26
+ const { InteractionCollector } = require('./InteractionCollector.js');
27
+ const { MessageMentions } = require('./MessageMentions.js');
28
+ const { MessagePayload } = require('./MessagePayload.js');
29
+ const { Poll } = require('./Poll.js');
30
+ const { ReactionCollector } = require('./ReactionCollector.js');
31
+ const { Sticker } = require('./Sticker.js');
32
+
33
+ /**
34
+ * Represents a message on Discord.
35
+ *
36
+ * @extends {Base}
37
+ */
38
+ class Message extends Base {
39
+ constructor(client, data) {
40
+ super(client);
41
+
42
+ /**
43
+ * The id of the channel the message was sent in
44
+ *
45
+ * @type {Snowflake}
46
+ */
47
+ this.channelId = data.channel_id;
48
+
49
+ /**
50
+ * The id of the guild the message was sent in, if any
51
+ *
52
+ * @type {?Snowflake}
53
+ */
54
+ this.guildId = data.guild_id ?? this.channel?.guild?.id ?? null;
55
+
56
+ this._patch(data);
57
+ }
58
+
59
+ _patch(data) {
60
+ /**
61
+ * The message's id
62
+ *
63
+ * @type {Snowflake}
64
+ */
65
+ this.id = data.id;
66
+
67
+ /**
68
+ * The timestamp the message was sent at
69
+ *
70
+ * @type {number}
71
+ */
72
+ this.createdTimestamp = DiscordSnowflake.timestampFrom(this.id);
73
+
74
+ if ('type' in data) {
75
+ /**
76
+ * The type of the message
77
+ *
78
+ * @type {?MessageType}
79
+ */
80
+ this.type = data.type;
81
+
82
+ /**
83
+ * Whether or not this message was sent by Discord, not actually a user (e.g. pin notifications)
84
+ *
85
+ * @type {?boolean}
86
+ */
87
+ this.system = !NonSystemMessageTypes.includes(this.type);
88
+ } else {
89
+ this.system ??= null;
90
+ this.type ??= null;
91
+ }
92
+
93
+ if ('content' in data) {
94
+ /**
95
+ * The content of the message.
96
+ * <info>This property requires the {@link GatewayIntentBits.MessageContent} privileged intent
97
+ * in a guild for messages that do not mention the client.</info>
98
+ *
99
+ * @type {?string}
100
+ */
101
+ this.content = data.content;
102
+ } else {
103
+ this.content ??= null;
104
+ }
105
+
106
+ if ('author' in data) {
107
+ /**
108
+ * The author of the message
109
+ *
110
+ * @type {?User}
111
+ */
112
+ this.author = this.client.users._add(data.author, !data.webhook_id);
113
+ } else {
114
+ this.author ??= null;
115
+ }
116
+
117
+ if ('pinned' in data) {
118
+ /**
119
+ * Whether or not this message is pinned
120
+ *
121
+ * @type {?boolean}
122
+ */
123
+ this.pinned = Boolean(data.pinned);
124
+ } else {
125
+ this.pinned ??= null;
126
+ }
127
+
128
+ if ('tts' in data) {
129
+ /**
130
+ * Whether or not the message was Text-To-Speech
131
+ *
132
+ * @type {?boolean}
133
+ */
134
+ this.tts = data.tts;
135
+ } else {
136
+ this.tts ??= null;
137
+ }
138
+
139
+ if ('nonce' in data) {
140
+ /**
141
+ * A random number or string used for checking message delivery
142
+ * <warn>This is only received after the message was sent successfully, and
143
+ * lost if re-fetched</warn>
144
+ *
145
+ * @type {?string}
146
+ */
147
+ this.nonce = data.nonce;
148
+ } else {
149
+ this.nonce ??= null;
150
+ }
151
+
152
+ if ('embeds' in data) {
153
+ /**
154
+ * An array of embeds in the message - e.g. YouTube Player.
155
+ * <info>This property requires the {@link GatewayIntentBits.MessageContent} privileged intent
156
+ * in a guild for messages that do not mention the client.</info>
157
+ *
158
+ * @type {Embed[]}
159
+ */
160
+ this.embeds = data.embeds.map(embed => new Embed(embed));
161
+ } else {
162
+ this.embeds = this.embeds?.slice() ?? [];
163
+ }
164
+
165
+ if ('components' in data) {
166
+ /**
167
+ * An array of components in the message.
168
+ * <info>This property requires the {@link GatewayIntentBits.MessageContent} privileged intent
169
+ * in a guild for messages that do not mention the client.</info>
170
+ *
171
+ * @type {Component[]}
172
+ */
173
+ this.components = data.components.map(component => createComponent(component));
174
+ } else {
175
+ this.components = this.components?.slice() ?? [];
176
+ }
177
+
178
+ if ('attachments' in data) {
179
+ /**
180
+ * A collection of attachments in the message - e.g. Pictures - mapped by their ids.
181
+ * <info>This property requires the {@link GatewayIntentBits.MessageContent} privileged intent
182
+ * in a guild for messages that do not mention the client.</info>
183
+ *
184
+ * @type {Collection<Snowflake, Attachment>}
185
+ */
186
+ this.attachments = new Collection();
187
+ if (data.attachments) {
188
+ for (const attachment of data.attachments) {
189
+ this.attachments.set(attachment.id, new Attachment(attachment));
190
+ }
191
+ }
192
+ } else {
193
+ this.attachments = new Collection(this.attachments);
194
+ }
195
+
196
+ if ('sticker_items' in data || 'stickers' in data) {
197
+ /**
198
+ * A collection of stickers in the message
199
+ *
200
+ * @type {Collection<Snowflake, Sticker>}
201
+ */
202
+ this.stickers = new Collection(
203
+ (data.sticker_items ?? data.stickers)?.map(sticker => [sticker.id, new Sticker(this.client, sticker)]),
204
+ );
205
+ } else {
206
+ this.stickers = new Collection(this.stickers);
207
+ }
208
+
209
+ if ('position' in data) {
210
+ /**
211
+ * A generally increasing integer (there may be gaps or duplicates) that represents
212
+ * the approximate position of the message in a thread.
213
+ *
214
+ * @type {?number}
215
+ */
216
+ this.position = data.position;
217
+ } else {
218
+ this.position ??= null;
219
+ }
220
+
221
+ if ('role_subscription_data' in data) {
222
+ /**
223
+ * Role subscription data found on {@link MessageType.RoleSubscriptionPurchase} messages.
224
+ *
225
+ * @typedef {Object} RoleSubscriptionData
226
+ * @property {Snowflake} roleSubscriptionListingId The id of the SKU and listing the user is subscribed to
227
+ * @property {string} tierName The name of the tier the user is subscribed to
228
+ * @property {number} totalMonthsSubscribed The total number of months the user has been subscribed for
229
+ * @property {boolean} isRenewal Whether this notification is a renewal
230
+ */
231
+
232
+ /**
233
+ * The data of the role subscription purchase or renewal.
234
+ * <info>This is present on {@link MessageType.RoleSubscriptionPurchase} messages.</info>
235
+ *
236
+ * @type {?RoleSubscriptionData}
237
+ */
238
+ this.roleSubscriptionData = {
239
+ roleSubscriptionListingId: data.role_subscription_data.role_subscription_listing_id,
240
+ tierName: data.role_subscription_data.tier_name,
241
+ totalMonthsSubscribed: data.role_subscription_data.total_months_subscribed,
242
+ isRenewal: data.role_subscription_data.is_renewal,
243
+ };
244
+ } else {
245
+ this.roleSubscriptionData ??= null;
246
+ }
247
+
248
+ if ('resolved' in data) {
249
+ /**
250
+ * Resolved data from auto-populated select menus.
251
+ *
252
+ * @type {?CommandInteractionResolvedData}
253
+ */
254
+ this.resolved = transformResolved(
255
+ { client: this.client, guild: this.guild, channel: this.channel },
256
+ data.resolved,
257
+ );
258
+ } else {
259
+ this.resolved ??= null;
260
+ }
261
+
262
+ // Discord sends null if the message has not been edited
263
+ if (data.edited_timestamp) {
264
+ /**
265
+ * The timestamp the message was last edited at (if applicable)
266
+ *
267
+ * @type {?number}
268
+ */
269
+ this.editedTimestamp = Date.parse(data.edited_timestamp);
270
+ } else {
271
+ this.editedTimestamp ??= null;
272
+ }
273
+
274
+ if ('reactions' in data) {
275
+ /**
276
+ * A manager of the reactions belonging to this message
277
+ *
278
+ * @type {ReactionManager}
279
+ */
280
+ this.reactions = new ReactionManager(this);
281
+ if (data.reactions?.length > 0) {
282
+ for (const reaction of data.reactions) {
283
+ this.reactions._add(reaction);
284
+ }
285
+ }
286
+ } else {
287
+ this.reactions ??= new ReactionManager(this);
288
+ }
289
+
290
+ /**
291
+ * All valid mentions that the message contains
292
+ *
293
+ * @type {MessageMentions}
294
+ */
295
+ this.mentions = new MessageMentions(
296
+ this,
297
+ data.mentions ?? this.mentions?.users,
298
+ data.mention_roles ?? this.mentions?.roles,
299
+ data.mention_everyone ?? this.mentions?.everyone,
300
+ data.mention_channels ?? this.mentions?.crosspostedChannels,
301
+ data.referenced_message?.author ?? this.mentions?.repliedUser,
302
+ );
303
+
304
+ if ('webhook_id' in data) {
305
+ /**
306
+ * The id of the webhook that sent the message, if applicable
307
+ *
308
+ * @type {?Snowflake}
309
+ */
310
+ this.webhookId = data.webhook_id;
311
+ } else {
312
+ this.webhookId ??= null;
313
+ }
314
+
315
+ if ('application' in data) {
316
+ /**
317
+ * Supplemental application information for group activities
318
+ *
319
+ * @type {?ClientApplication}
320
+ */
321
+ this.groupActivityApplication = new ClientApplication(this.client, data.application);
322
+ } else {
323
+ this.groupActivityApplication ??= null;
324
+ }
325
+
326
+ if ('application_id' in data) {
327
+ /**
328
+ * The id of the application of the interaction that sent this message, if any
329
+ *
330
+ * @type {?Snowflake}
331
+ */
332
+ this.applicationId = data.application_id;
333
+ } else {
334
+ this.applicationId ??= null;
335
+ }
336
+
337
+ if ('activity' in data) {
338
+ /**
339
+ * Group activity
340
+ *
341
+ * @type {?MessageActivity}
342
+ */
343
+ this.activity = {
344
+ partyId: data.activity.party_id,
345
+ type: data.activity.type,
346
+ };
347
+ } else {
348
+ this.activity ??= null;
349
+ }
350
+
351
+ if ('thread' in data) {
352
+ this.client.channels._add(data.thread, this.guild);
353
+ }
354
+
355
+ if (this.member && data.member) {
356
+ this.member._patch(data.member);
357
+ } else if (data.member && this.guild && this.author) {
358
+ this.guild.members._add(Object.assign(data.member, { user: this.author }));
359
+ }
360
+
361
+ if ('flags' in data) {
362
+ /**
363
+ * Flags that are applied to the message
364
+ *
365
+ * @type {Readonly<MessageFlagsBitField>}
366
+ */
367
+ this.flags = new MessageFlagsBitField(data.flags).freeze();
368
+ } else {
369
+ this.flags = new MessageFlagsBitField(this.flags).freeze();
370
+ }
371
+
372
+ /**
373
+ * Reference data sent in a message that contains ids identifying the referenced message.
374
+ * This can be present in the following types of message:
375
+ * - {@link MessageFlags.Crossposted}
376
+ * - {@link MessageType.ChannelPinnedMessage}
377
+ * - {@link MessageType.ChannelFollowAdd}
378
+ * - {@link MessageType.Reply}
379
+ * - {@link MessageType.ThreadStarterMessage}
380
+ *
381
+ * @see {@link https://discord.com/developers/docs/resources/message#message-object-message-types}
382
+ * @typedef {Object} MessageReference
383
+ * @property {Snowflake} channelId The channel id that was referenced
384
+ * @property {Snowflake|undefined} guildId The guild id that was referenced
385
+ * @property {Snowflake|undefined} messageId The message id that was referenced
386
+ * @property {MessageReferenceType} type The type of message reference
387
+ */
388
+
389
+ if ('message_reference' in data) {
390
+ /**
391
+ * Message reference data
392
+ *
393
+ * @type {?MessageReference}
394
+ */
395
+ this.reference = {
396
+ channelId: data.message_reference.channel_id,
397
+ guildId: data.message_reference.guild_id,
398
+ messageId: data.message_reference.message_id,
399
+ type: data.message_reference.type,
400
+ };
401
+ } else {
402
+ this.reference ??= null;
403
+ }
404
+
405
+ if (data.referenced_message) {
406
+ this.channel?.messages._add({ guild_id: data.message_reference?.guild_id, ...data.referenced_message });
407
+ }
408
+
409
+ if (data.interaction_metadata) {
410
+ /**
411
+ * Partial data of the interaction that a message is a result of
412
+ *
413
+ * @typedef {Object} MessageInteractionMetadata
414
+ * @property {Snowflake} id The interaction's id
415
+ * @property {InteractionType} type The type of the interaction
416
+ * @property {User} user The user that invoked the interaction
417
+ * @property {AuthorizingIntegrationOwners} authorizingIntegrationOwners
418
+ * Mapping of integration types that the application was authorized for the related user or guild ids
419
+ * @property {?Snowflake} originalResponseMessageId
420
+ * Id of the original response message. Present only on follow-up messages
421
+ * @property {?Snowflake} interactedMessageId
422
+ * Id of the message that contained interactive component.
423
+ * Present only on messages created from component interactions
424
+ * @property {?MessageInteractionMetadata} triggeringInteractionMetadata
425
+ * Metadata for the interaction that was used to open the modal. Present only on modal submit interactions
426
+ */
427
+
428
+ /**
429
+ * Partial data of the interaction that this message is a result of
430
+ *
431
+ * @type {?MessageInteractionMetadata}
432
+ */
433
+ this.interactionMetadata = _transformAPIMessageInteractionMetadata(this.client, data.interaction_metadata);
434
+ } else {
435
+ this.interactionMetadata ??= null;
436
+ }
437
+
438
+ if (data.poll) {
439
+ if (this.poll) {
440
+ this.poll._patch(data.poll);
441
+ } else {
442
+ /**
443
+ * The poll that was sent with the message
444
+ *
445
+ * @type {?Poll}
446
+ */
447
+ this.poll = new Poll(this.client, data.poll, this, this.channel);
448
+ }
449
+ } else {
450
+ this.poll ??= null;
451
+ }
452
+
453
+ if (data.message_snapshots) {
454
+ /**
455
+ * The message snapshots associated with the message reference
456
+ *
457
+ * @type {Collection<Snowflake, Message>}
458
+ */
459
+ this.messageSnapshots = data.message_snapshots.reduce((coll, snapshot) => {
460
+ const channel = this.client.channels.resolve(this.reference.channelId);
461
+ const snapshotData = {
462
+ ...snapshot.message,
463
+ id: this.reference.messageId,
464
+ channel_id: this.reference.channelId,
465
+ guild_id: this.reference.guildId,
466
+ };
467
+
468
+ return coll.set(
469
+ this.reference.messageId,
470
+ channel ? channel.messages._add(snapshotData) : new this.constructor(this.client, snapshotData),
471
+ );
472
+ }, new Collection());
473
+ } else {
474
+ this.messageSnapshots ??= new Collection();
475
+ }
476
+
477
+ /**
478
+ * A call associated with a message
479
+ *
480
+ * @typedef {Object} MessageCall
481
+ * @property {Readonly<?Date>} endedAt The time the call ended
482
+ * @property {?number} endedTimestamp The timestamp the call ended
483
+ * @property {Snowflake[]} participants The ids of the users that participated in the call
484
+ */
485
+
486
+ if (data.call) {
487
+ /**
488
+ * The call associated with the message
489
+ *
490
+ * @type {?MessageCall}
491
+ */
492
+ this.call = {
493
+ endedTimestamp: data.call.ended_timestamp ? Date.parse(data.call.ended_timestamp) : null,
494
+ participants: data.call.participants,
495
+ get endedAt() {
496
+ return this.endedTimestamp && new Date(this.endedTimestamp);
497
+ },
498
+ };
499
+ } else {
500
+ this.call ??= null;
501
+ }
502
+
503
+ /**
504
+ * The shared client theme sent with this message
505
+ *
506
+ * @typedef {Object} SharedClientTheme
507
+ * @property {string[]} colors The hexadecimal-encoded colors of the theme (max of 5)
508
+ * @property {number} gradientAngle The direction of the theme's colors (0–360)
509
+ * @property {number} baseMix The intensity of the theme's colors (0–100)
510
+ * @property {?BaseThemeType} [baseTheme] The mode of the theme
511
+ */
512
+ if (data.shared_client_theme) {
513
+ /**
514
+ * The shared client theme sent with this message
515
+ *
516
+ * @type {?SharedClientTheme}
517
+ */
518
+ this.sharedClientTheme = {
519
+ colors: data.shared_client_theme.colors,
520
+ gradientAngle: data.shared_client_theme.gradient_angle,
521
+ baseMix: data.shared_client_theme.base_mix,
522
+ };
523
+
524
+ if ('base_theme' in data.shared_client_theme) {
525
+ this.sharedClientTheme.baseTheme = data.shared_client_theme.base_theme;
526
+ }
527
+ } else {
528
+ this.sharedClientTheme ??= null;
529
+ }
530
+ }
531
+
532
+ /**
533
+ * The channel that the message was sent in
534
+ *
535
+ * @type {TextBasedChannels}
536
+ * @readonly
537
+ */
538
+ get channel() {
539
+ return this.client.channels.resolve(this.channelId);
540
+ }
541
+
542
+ /**
543
+ * Whether or not this message is a partial
544
+ *
545
+ * @type {boolean}
546
+ * @readonly
547
+ */
548
+ get partial() {
549
+ return typeof this.content !== 'string' || !this.author;
550
+ }
551
+
552
+ /**
553
+ * Represents the author of the message as a guild member.
554
+ * Only available if the message comes from a guild where the author is still a member
555
+ *
556
+ * @type {?GuildMember}
557
+ * @readonly
558
+ */
559
+ get member() {
560
+ return this.guild?.members.resolve(this.author) ?? null;
561
+ }
562
+
563
+ /**
564
+ * The time the message was sent at
565
+ *
566
+ * @type {Date}
567
+ * @readonly
568
+ */
569
+ get createdAt() {
570
+ return new Date(this.createdTimestamp);
571
+ }
572
+
573
+ /**
574
+ * The time the message was last edited at (if applicable)
575
+ *
576
+ * @type {?Date}
577
+ * @readonly
578
+ */
579
+ get editedAt() {
580
+ return this.editedTimestamp && new Date(this.editedTimestamp);
581
+ }
582
+
583
+ /**
584
+ * The guild the message was sent in (if in a guild channel)
585
+ *
586
+ * @type {?Guild}
587
+ * @readonly
588
+ */
589
+ get guild() {
590
+ return this.client.guilds.resolve(this.guildId) ?? this.channel?.guild ?? null;
591
+ }
592
+
593
+ /**
594
+ * Whether this message has a thread associated with it
595
+ *
596
+ * @type {boolean}
597
+ * @readonly
598
+ */
599
+ get hasThread() {
600
+ return this.flags.has(MessageFlags.HasThread);
601
+ }
602
+
603
+ /**
604
+ * The thread started by this message
605
+ * <info>This property is not suitable for checking whether a message has a thread,
606
+ * use {@link Message#hasThread} instead.</info>
607
+ *
608
+ * @type {?ThreadChannel}
609
+ * @readonly
610
+ */
611
+ get thread() {
612
+ return this.channel?.threads?.cache.get(this.id) ?? null;
613
+ }
614
+
615
+ /**
616
+ * The URL to jump to this message
617
+ *
618
+ * @type {string}
619
+ * @readonly
620
+ */
621
+ get url() {
622
+ return this.inGuild() ? messageLink(this.channelId, this.id, this.guildId) : messageLink(this.channelId, this.id);
623
+ }
624
+
625
+ /**
626
+ * The message contents with all mentions replaced by the equivalent text.
627
+ * If mentions cannot be resolved to a name, the relevant mention in the message content will not be converted.
628
+ *
629
+ * @type {?string}
630
+ * @readonly
631
+ */
632
+ get cleanContent() {
633
+ // eslint-disable-next-line eqeqeq
634
+ return this.content != null && this.channel ? cleanContent(this.content, this.channel) : null;
635
+ }
636
+
637
+ /**
638
+ * Creates a reaction collector.
639
+ *
640
+ * @param {ReactionCollectorOptions} [options={}] Options to send to the collector
641
+ * @returns {ReactionCollector}
642
+ * @example
643
+ * // Create a reaction collector
644
+ * const filter = (reaction, user) => reaction.emoji.name === '👌' && user.id === 'someId';
645
+ * const collector = message.createReactionCollector({ filter, time: 15_000 });
646
+ * collector.on('collect', r => console.log(`Collected ${r.emoji.name}`));
647
+ * collector.on('end', collected => console.log(`Collected ${collected.size} items`));
648
+ */
649
+ createReactionCollector(options = {}) {
650
+ return new ReactionCollector(this, options);
651
+ }
652
+
653
+ /**
654
+ * An object containing the same properties as CollectorOptions, but a few more:
655
+ *
656
+ * @typedef {ReactionCollectorOptions} AwaitReactionsOptions
657
+ * @property {string[]} [errors] Stop/end reasons that cause the promise to reject
658
+ */
659
+
660
+ /**
661
+ * Similar to createReactionCollector but in promise form.
662
+ * Resolves with a collection of reactions that pass the specified filter.
663
+ *
664
+ * @param {AwaitReactionsOptions} [options={}] Optional options to pass to the internal collector
665
+ * @returns {Promise<Collection<string|Snowflake, MessageReaction>>}
666
+ * @example
667
+ * // Create a reaction collector
668
+ * const filter = (reaction, user) => reaction.emoji.name === '👌' && user.id === 'someId'
669
+ * message.awaitReactions({ filter, time: 15_000 })
670
+ * .then(collected => console.log(`Collected ${collected.size} reactions`))
671
+ * .catch(console.error);
672
+ */
673
+ async awaitReactions(options = {}) {
674
+ return new Promise((resolve, reject) => {
675
+ const collector = this.createReactionCollector(options);
676
+ collector.once('end', (reactions, reason) => {
677
+ if (options.errors?.includes(reason)) reject(reactions);
678
+ else resolve(reactions);
679
+ });
680
+ });
681
+ }
682
+
683
+ /**
684
+ * @typedef {CollectorOptions} MessageComponentCollectorOptions
685
+ * @property {ComponentType} [componentType] The type of component to listen for
686
+ * @property {number} [max] The maximum total amount of interactions to collect
687
+ * @property {number} [maxComponents] The maximum number of components to collect
688
+ * @property {number} [maxUsers] The maximum number of users to interact
689
+ */
690
+
691
+ /**
692
+ * Creates a message component interaction collector.
693
+ *
694
+ * @param {MessageComponentCollectorOptions} [options={}] Options to send to the collector
695
+ * @returns {InteractionCollector}
696
+ * @example
697
+ * // Create a message component interaction collector
698
+ * const filter = (interaction) => interaction.customId === 'button' && interaction.user.id === 'someId';
699
+ * const collector = message.createMessageComponentCollector({ filter, time: 15_000 });
700
+ * collector.on('collect', i => console.log(`Collected ${i.customId}`));
701
+ * collector.on('end', collected => console.log(`Collected ${collected.size} items`));
702
+ */
703
+ createMessageComponentCollector(options = {}) {
704
+ return new InteractionCollector(this.client, {
705
+ ...options,
706
+ interactionType: InteractionType.MessageComponent,
707
+ message: this,
708
+ });
709
+ }
710
+
711
+ /**
712
+ * An object containing the same properties as CollectorOptions, but a few more:
713
+ *
714
+ * @typedef {Object} AwaitMessageComponentOptions
715
+ * @property {CollectorFilter} [filter] The filter applied to this collector
716
+ * @property {number} [time] Time to wait for an interaction before rejecting
717
+ * @property {ComponentType} [componentType] The type of component interaction to collect
718
+ * @property {number} [idle] Time to wait without another message component interaction before ending the collector
719
+ * @property {boolean} [dispose] Whether to remove the message component interaction after collecting
720
+ */
721
+
722
+ /**
723
+ * Collects a single component interaction that passes the filter.
724
+ * The Promise will reject if the time expires.
725
+ *
726
+ * @param {AwaitMessageComponentOptions} [options={}] Options to pass to the internal collector
727
+ * @returns {Promise<MessageComponentInteraction>}
728
+ * @example
729
+ * // Collect a message component interaction
730
+ * const filter = (interaction) => interaction.customId === 'button' && interaction.user.id === 'someId';
731
+ * message.awaitMessageComponent({ filter, time: 15_000 })
732
+ * .then(interaction => console.log(`${interaction.customId} was clicked!`))
733
+ * .catch(console.error);
734
+ */
735
+ async awaitMessageComponent(options = {}) {
736
+ const _options = { ...options, max: 1 };
737
+ return new Promise((resolve, reject) => {
738
+ const collector = this.createMessageComponentCollector(_options);
739
+ collector.once('end', (interactions, reason) => {
740
+ const interaction = interactions.first();
741
+ if (interaction) resolve(interaction);
742
+ else reject(new DiscordjsError(ErrorCodes.InteractionCollectorError, reason));
743
+ });
744
+ });
745
+ }
746
+
747
+ /**
748
+ * Whether the message is editable by the client user
749
+ *
750
+ * @type {boolean}
751
+ * @readonly
752
+ */
753
+ get editable() {
754
+ const precheck = Boolean(
755
+ this.author.id === this.client.user.id &&
756
+ (!this.guild || this.channel?.viewable) &&
757
+ this.reference?.type !== MessageReferenceType.Forward,
758
+ );
759
+
760
+ // Regardless of permissions thread messages cannot be edited if
761
+ // the thread is archived or the thread is locked and the bot does not have permission to manage threads.
762
+ if (this.channel?.isThread()) {
763
+ if (this.channel.archived) return false;
764
+ if (this.channel.locked) {
765
+ const permissions = this.channel.permissionsFor(this.client.user);
766
+ if (!permissions?.has(PermissionFlagsBits.ManageThreads, true)) return false;
767
+ }
768
+ }
769
+
770
+ return precheck;
771
+ }
772
+
773
+ /**
774
+ * Whether the message is deletable by the client user
775
+ *
776
+ * @type {boolean}
777
+ * @readonly
778
+ */
779
+ get deletable() {
780
+ if (UndeletableMessageTypes.includes(this.type)) return false;
781
+
782
+ if (!this.guild) {
783
+ return this.author.id === this.client.user.id;
784
+ }
785
+
786
+ // DMChannel does not have viewable property, so check viewable after proved that message is on a guild.
787
+ if (!this.channel?.viewable) {
788
+ return false;
789
+ }
790
+
791
+ const permissions = this.channel?.permissionsFor(this.client.user);
792
+ if (!permissions) return false;
793
+ // This flag allows deleting even if timed out
794
+ if (permissions.has(PermissionFlagsBits.Administrator, false)) return true;
795
+
796
+ // The auto moderation action message author is the reference message author
797
+ return (
798
+ (this.type !== MessageType.AutoModerationAction && this.author.id === this.client.user.id) ||
799
+ (permissions.has(PermissionFlagsBits.ManageMessages, false) && !this.guild.members.me.isCommunicationDisabled())
800
+ );
801
+ }
802
+
803
+ /**
804
+ * Whether the message is bulk deletable by the client user
805
+ *
806
+ * @type {boolean}
807
+ * @readonly
808
+ * @example
809
+ * // Filter for bulk deletable messages
810
+ * channel.bulkDelete(messages.filter(message => message.bulkDeletable));
811
+ */
812
+ get bulkDeletable() {
813
+ return (
814
+ (this.inGuild() &&
815
+ Date.now() - this.createdTimestamp < MaxBulkDeletableMessageAge &&
816
+ this.deletable &&
817
+ this.channel?.permissionsFor(this.client.user).has(PermissionFlagsBits.ManageMessages, false)) ??
818
+ false
819
+ );
820
+ }
821
+
822
+ /**
823
+ * Whether the message is pinnable by the client user
824
+ *
825
+ * @type {boolean}
826
+ * @readonly
827
+ */
828
+ get pinnable() {
829
+ const { channel } = this;
830
+
831
+ if (this.system) return false;
832
+ if (!this.guild) return true;
833
+ if (!channel || channel.isVoiceBased() || !channel.viewable) return false;
834
+
835
+ const permissions = channel.permissionsFor(this.client.user);
836
+ if (!permissions) return false;
837
+
838
+ return permissions.has(PermissionFlagsBits.ReadMessageHistory | PermissionFlagsBits.PinMessages);
839
+ }
840
+
841
+ /**
842
+ * Fetches the Message this crosspost/reply/pin-add references, if available to the client
843
+ *
844
+ * @returns {Promise<Message>}
845
+ */
846
+ async fetchReference() {
847
+ if (!this.reference) throw new DiscordjsError(ErrorCodes.MessageReferenceMissing);
848
+ const { channelId, messageId } = this.reference;
849
+ if (!messageId) throw new DiscordjsError(ErrorCodes.MessageReferenceMissing);
850
+ const channel = this.client.channels.resolve(channelId);
851
+ if (!channel) throw new DiscordjsError(ErrorCodes.GuildChannelResolve);
852
+ return channel.messages.fetch(messageId);
853
+ }
854
+
855
+ /**
856
+ * Whether the message is crosspostable by the client user
857
+ *
858
+ * @type {boolean}
859
+ * @readonly
860
+ */
861
+ get crosspostable() {
862
+ const bitfield =
863
+ PermissionFlagsBits.SendMessages |
864
+ (this.author.id === this.client.user.id ? PermissionsBitField.DefaultBit : PermissionFlagsBits.ManageMessages);
865
+ const { channel } = this;
866
+ return Boolean(
867
+ channel?.type === ChannelType.GuildAnnouncement &&
868
+ !this.flags.has(MessageFlags.Crossposted) &&
869
+ this.reference?.type !== MessageReferenceType.Forward &&
870
+ this.type === MessageType.Default &&
871
+ !this.poll &&
872
+ channel.viewable &&
873
+ channel.permissionsFor(this.client.user)?.has(bitfield, false),
874
+ );
875
+ }
876
+
877
+ /**
878
+ * Edits the content of the message.
879
+ *
880
+ * @param {string|MessageEditOptions|MessagePayload|FileBodyEncodable<RESTPatchAPIChannelMessageJSONBody>|JSONEncodable<RESTPatchAPIChannelMessageJSONBody>} options The options to provide
881
+ * @returns {Promise<Message>}
882
+ * @example
883
+ * // Update the content of a message
884
+ * message.edit('This is my new content!')
885
+ * .then(msg => console.log(`Updated the content of a message to ${msg.content}`))
886
+ * .catch(console.error);
887
+ */
888
+ async edit(options) {
889
+ if (!this.channel) throw new DiscordjsError(ErrorCodes.ChannelNotCached);
890
+ return this.channel.messages.edit(this, options);
891
+ }
892
+
893
+ /**
894
+ * Publishes a message in an announcement channel to all channels following it.
895
+ *
896
+ * @returns {Promise<Message>}
897
+ * @example
898
+ * // Crosspost a message
899
+ * if (message.channel.type === ChannelType.GuildAnnouncement) {
900
+ * message.crosspost()
901
+ * .then(() => console.log('Crossposted message'))
902
+ * .catch(console.error);
903
+ * }
904
+ */
905
+ async crosspost() {
906
+ if (!this.channel) throw new DiscordjsError(ErrorCodes.ChannelNotCached);
907
+ return this.channel.messages.crosspost(this.id);
908
+ }
909
+
910
+ /**
911
+ * Pins this message to the channel's pinned messages.
912
+ *
913
+ * @param {string} [reason] Reason for pinning
914
+ * @returns {Promise<Message>}
915
+ * @example
916
+ * // Pin a message
917
+ * message.pin()
918
+ * .then(console.log)
919
+ * .catch(console.error)
920
+ */
921
+ async pin(reason) {
922
+ if (!this.channel) throw new DiscordjsError(ErrorCodes.ChannelNotCached);
923
+ await this.channel.messages.pin(this.id, reason);
924
+ return this;
925
+ }
926
+
927
+ /**
928
+ * Unpins this message from the channel's pinned messages.
929
+ *
930
+ * @param {string} [reason] Reason for unpinning
931
+ * @returns {Promise<Message>}
932
+ * @example
933
+ * // Unpin a message
934
+ * message.unpin()
935
+ * .then(console.log)
936
+ * .catch(console.error)
937
+ */
938
+ async unpin(reason) {
939
+ if (!this.channel) throw new DiscordjsError(ErrorCodes.ChannelNotCached);
940
+ await this.channel.messages.unpin(this.id, reason);
941
+ return this;
942
+ }
943
+
944
+ /**
945
+ * Adds a reaction to the message.
946
+ *
947
+ * @param {EmojiIdentifierResolvable} emoji The emoji to react with
948
+ * @returns {Promise<MessageReaction>}
949
+ * @example
950
+ * // React to a message with a unicode emoji
951
+ * message.react('🤔')
952
+ * .then(console.log)
953
+ * .catch(console.error);
954
+ * @example
955
+ * // React to a message with a custom emoji
956
+ * message.react(message.guild.emojis.cache.get('123456789012345678'))
957
+ * .then(console.log)
958
+ * .catch(console.error);
959
+ */
960
+ async react(emoji) {
961
+ if (!this.channel) throw new DiscordjsError(ErrorCodes.ChannelNotCached);
962
+ await this.channel.messages.react(this.id, emoji);
963
+
964
+ return this.client.actions.MessageReactionAdd.handle(
965
+ {
966
+ [this.client.actions.injectedUser]: this.client.user,
967
+ [this.client.actions.injectedChannel]: this.channel,
968
+ [this.client.actions.injectedMessage]: this,
969
+ emoji: resolvePartialEmoji(emoji),
970
+ },
971
+ true,
972
+ ).reaction;
973
+ }
974
+
975
+ /**
976
+ * Deletes the message.
977
+ *
978
+ * @returns {Promise<Message>}
979
+ * @example
980
+ * // Delete a message
981
+ * message.delete()
982
+ * .then(msg => console.log(`Deleted message from ${msg.author.username}`))
983
+ * .catch(console.error);
984
+ */
985
+ async delete() {
986
+ if (!this.channel) throw new DiscordjsError(ErrorCodes.ChannelNotCached);
987
+ await this.channel.messages.delete(this.id);
988
+ return this;
989
+ }
990
+
991
+ /**
992
+ * Options provided when sending a message as an inline reply.
993
+ *
994
+ * @typedef {BaseMessageCreateOptions} MessageReplyOptions
995
+ * @property {boolean} [failIfNotExists=this.client.options.failIfNotExists] Whether to error if the referenced
996
+ * message does not exist (creates a standard message in this case when false)
997
+ */
998
+
999
+ /**
1000
+ * Send an inline reply to this message.
1001
+ *
1002
+ * @param {string|MessagePayload|MessageReplyOptions} options The options to provide
1003
+ * @returns {Promise<Message>}
1004
+ * @example
1005
+ * // Reply to a message
1006
+ * message.reply('This is a reply!')
1007
+ * .then(() => console.log(`Replied to message "${message.content}"`))
1008
+ * .catch(console.error);
1009
+ */
1010
+ async reply(options) {
1011
+ let data;
1012
+
1013
+ if (options instanceof MessagePayload) {
1014
+ data = options;
1015
+ } else {
1016
+ data = MessagePayload.create(this, options, {
1017
+ messageReference: {
1018
+ messageId: this.id,
1019
+ channelId: this.channelId,
1020
+ guildId: this.guildId ?? undefined,
1021
+ type: MessageReferenceType.Default,
1022
+ failIfNotExists: options?.failIfNotExists ?? this.client.options.failIfNotExists,
1023
+ },
1024
+ });
1025
+ }
1026
+
1027
+ return this.client.channels.createMessage(this.channelId, data);
1028
+ }
1029
+
1030
+ /**
1031
+ * Forwards this message.
1032
+ *
1033
+ * @param {TextChannelResolvable} channel The channel to forward this message to.
1034
+ * @returns {Promise<Message>}
1035
+ */
1036
+ async forward(channel) {
1037
+ return this.client.channels.createMessage(channel, {
1038
+ messageReference: {
1039
+ messageId: this.id,
1040
+ channelId: this.channelId,
1041
+ guildId: this.guildId ?? undefined,
1042
+ type: MessageReferenceType.Forward,
1043
+ },
1044
+ });
1045
+ }
1046
+
1047
+ /**
1048
+ * Options for starting a thread on a message.
1049
+ *
1050
+ * @typedef {Object} StartThreadOptions
1051
+ * @property {string} name The name of the new thread
1052
+ * @property {ThreadAutoArchiveDuration} [autoArchiveDuration=this.channel.defaultAutoArchiveDuration] The amount of
1053
+ * time after which the thread should automatically archive in case of no recent activity
1054
+ * @property {string} [reason] Reason for creating the thread
1055
+ * @property {number} [rateLimitPerUser] The rate limit per user (slowmode) for the thread in seconds
1056
+ */
1057
+
1058
+ /**
1059
+ * Create a new public thread from this message
1060
+ *
1061
+ * @see GuildTextThreadManager#create
1062
+ * @param {StartThreadOptions} [options] Options for starting a thread on this message
1063
+ * @returns {Promise<ThreadChannel>}
1064
+ */
1065
+ async startThread(options = {}) {
1066
+ if (!this.channel) throw new DiscordjsError(ErrorCodes.ChannelNotCached);
1067
+ if (![ChannelType.GuildText, ChannelType.GuildAnnouncement].includes(this.channel.type)) {
1068
+ throw new DiscordjsError(ErrorCodes.MessageThreadParent);
1069
+ }
1070
+
1071
+ if (this.hasThread) throw new DiscordjsError(ErrorCodes.MessageExistingThread);
1072
+ return this.channel.threads.create({ ...options, startMessage: this });
1073
+ }
1074
+
1075
+ /**
1076
+ * Fetch this message.
1077
+ *
1078
+ * @param {boolean} [force=true] Whether to skip the cache check and request the API
1079
+ * @returns {Promise<Message>}
1080
+ */
1081
+ async fetch(force = true) {
1082
+ if (!this.channel) throw new DiscordjsError(ErrorCodes.ChannelNotCached);
1083
+ return this.channel.messages.fetch({ message: this.id, force });
1084
+ }
1085
+
1086
+ /**
1087
+ * Fetches the webhook used to create this message.
1088
+ *
1089
+ * @returns {Promise<?Webhook>}
1090
+ */
1091
+ async fetchWebhook() {
1092
+ if (!this.webhookId) throw new DiscordjsError(ErrorCodes.WebhookMessage);
1093
+ if (this.webhookId === this.applicationId) throw new DiscordjsError(ErrorCodes.WebhookApplication);
1094
+ return this.client.fetchWebhook(this.webhookId);
1095
+ }
1096
+
1097
+ /**
1098
+ * Suppresses or unsuppresses embeds on a message.
1099
+ *
1100
+ * @param {boolean} [suppress=true] If the embeds should be suppressed or not
1101
+ * @returns {Promise<Message>}
1102
+ */
1103
+ async suppressEmbeds(suppress = true) {
1104
+ const flags = new MessageFlagsBitField(this.flags.bitfield);
1105
+
1106
+ if (suppress) {
1107
+ flags.add(MessageFlags.SuppressEmbeds);
1108
+ } else {
1109
+ flags.remove(MessageFlags.SuppressEmbeds);
1110
+ }
1111
+
1112
+ return this.edit({ flags });
1113
+ }
1114
+
1115
+ /**
1116
+ * Removes the attachments from this message.
1117
+ *
1118
+ * @returns {Promise<Message>}
1119
+ */
1120
+ async removeAttachments() {
1121
+ return this.edit({ attachments: [] });
1122
+ }
1123
+
1124
+ /**
1125
+ * Resolves a component by a custom id.
1126
+ *
1127
+ * @param {string} customId The custom id to resolve against
1128
+ * @returns {?MessageActionRowComponent}
1129
+ */
1130
+ resolveComponent(customId) {
1131
+ return findComponentByCustomId(this.components, customId);
1132
+ }
1133
+
1134
+ /**
1135
+ * Used mainly internally. Whether two messages are identical in properties. If you want to compare messages
1136
+ * without checking all the properties, use `message.id === message2.id`, which is much more efficient. This
1137
+ * method allows you to see if there are differences in content, embeds, attachments, nonce and tts properties.
1138
+ *
1139
+ * @param {Message} message The message to compare it to
1140
+ * @param {APIMessage} [rawData] Raw data passed through the WebSocket about this message
1141
+ * @returns {boolean}
1142
+ */
1143
+ equals(message, rawData) {
1144
+ if (!message) return false;
1145
+ const embedUpdate = !message.author && !message.attachments;
1146
+ if (embedUpdate) return this.id === message.id && this.embeds.length === message.embeds.length;
1147
+
1148
+ let equal =
1149
+ this.id === message.id &&
1150
+ this.author.id === message.author.id &&
1151
+ this.content === message.content &&
1152
+ this.nonce === message.nonce &&
1153
+ this.tts === message.tts &&
1154
+ this.attachments.size === message.attachments.size &&
1155
+ this.embeds.length === message.embeds.length &&
1156
+ this.attachments.every(attachment => message.attachments.has(attachment.id)) &&
1157
+ this.embeds.every((embed, index) => embed.equals(message.embeds[index]));
1158
+
1159
+ if (equal && rawData) {
1160
+ equal =
1161
+ this.mentions.everyone === message.mentions.everyone &&
1162
+ this.createdTimestamp === Date.parse(rawData.timestamp) &&
1163
+ this.editedTimestamp === Date.parse(rawData.edited_timestamp);
1164
+ }
1165
+
1166
+ return equal;
1167
+ }
1168
+
1169
+ /**
1170
+ * Whether this message is from a guild.
1171
+ *
1172
+ * @returns {boolean}
1173
+ */
1174
+ inGuild() {
1175
+ return Boolean(this.guildId);
1176
+ }
1177
+
1178
+ /**
1179
+ * When concatenated with a string, this automatically concatenates the message's content instead of the object.
1180
+ *
1181
+ * @returns {string}
1182
+ * @example
1183
+ * // Logs: Message: This is a message!
1184
+ * console.log(`Message: ${message}`);
1185
+ */
1186
+ toString() {
1187
+ return this.content;
1188
+ }
1189
+
1190
+ toJSON() {
1191
+ return super.toJSON({
1192
+ channel: 'channelId',
1193
+ author: 'authorId',
1194
+ groupActivityApplication: 'groupActivityApplicationId',
1195
+ guild: 'guildId',
1196
+ cleanContent: true,
1197
+ member: false,
1198
+ reactions: false,
1199
+ });
1200
+ }
1201
+ }
1202
+
1203
+ exports.Message = Message;