discord.js 15.0.0-dev.1748650424-ef2c1bfa7 → 15.0.0-dev.1749297897-970871720

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 (285) hide show
  1. package/package.json +7 -10
  2. package/src/client/BaseClient.js +8 -0
  3. package/src/client/Client.js +84 -15
  4. package/src/client/WebhookClient.js +22 -6
  5. package/src/client/actions/Action.js +1 -0
  6. package/src/client/actions/ActionsManager.js +2 -0
  7. package/src/client/actions/ChannelCreate.js +3 -1
  8. package/src/client/actions/ChannelDelete.js +2 -1
  9. package/src/client/actions/ChannelUpdate.js +1 -1
  10. package/src/client/actions/GuildEmojiCreate.js +2 -1
  11. package/src/client/actions/GuildEmojiDelete.js +2 -1
  12. package/src/client/actions/GuildEmojiUpdate.js +2 -1
  13. package/src/client/actions/GuildMemberRemove.js +4 -1
  14. package/src/client/actions/GuildMemberUpdate.js +3 -1
  15. package/src/client/actions/GuildRoleCreate.js +3 -1
  16. package/src/client/actions/GuildRoleDelete.js +2 -1
  17. package/src/client/actions/GuildScheduledEventDelete.js +2 -1
  18. package/src/client/actions/GuildScheduledEventUserAdd.js +2 -1
  19. package/src/client/actions/GuildScheduledEventUserRemove.js +2 -1
  20. package/src/client/actions/GuildSoundboardSoundDelete.js +2 -1
  21. package/src/client/actions/GuildStickerCreate.js +2 -1
  22. package/src/client/actions/GuildStickerDelete.js +2 -1
  23. package/src/client/actions/GuildStickerUpdate.js +2 -1
  24. package/src/client/actions/GuildUpdate.js +2 -1
  25. package/src/client/actions/InteractionCreate.js +4 -1
  26. package/src/client/actions/MessageCreate.js +2 -1
  27. package/src/client/actions/MessageDelete.js +2 -1
  28. package/src/client/actions/MessageDeleteBulk.js +3 -1
  29. package/src/client/actions/MessagePollVoteAdd.js +2 -1
  30. package/src/client/actions/MessagePollVoteRemove.js +2 -1
  31. package/src/client/actions/MessageReactionAdd.js +3 -1
  32. package/src/client/actions/MessageReactionRemove.js +2 -1
  33. package/src/client/actions/MessageReactionRemoveAll.js +2 -1
  34. package/src/client/actions/MessageReactionRemoveEmoji.js +2 -1
  35. package/src/client/actions/StageInstanceCreate.js +2 -1
  36. package/src/client/actions/StageInstanceDelete.js +2 -1
  37. package/src/client/actions/StageInstanceUpdate.js +2 -1
  38. package/src/client/actions/ThreadCreate.js +3 -1
  39. package/src/client/actions/ThreadMembersUpdate.js +3 -1
  40. package/src/client/actions/TypingStart.js +2 -1
  41. package/src/client/actions/UserUpdate.js +2 -1
  42. package/src/client/voice/ClientVoiceManager.js +2 -0
  43. package/src/client/websocket/handlers/APPLICATION_COMMAND_PERMISSIONS_UPDATE.js +1 -0
  44. package/src/client/websocket/handlers/AUTO_MODERATION_ACTION_EXECUTION.js +1 -0
  45. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_CREATE.js +1 -0
  46. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_DELETE.js +1 -0
  47. package/src/client/websocket/handlers/AUTO_MODERATION_RULE_UPDATE.js +1 -0
  48. package/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.js +1 -0
  49. package/src/client/websocket/handlers/CHANNEL_UPDATE.js +1 -0
  50. package/src/client/websocket/handlers/ENTITLEMENT_CREATE.js +1 -0
  51. package/src/client/websocket/handlers/ENTITLEMENT_DELETE.js +1 -0
  52. package/src/client/websocket/handlers/ENTITLEMENT_UPDATE.js +1 -0
  53. package/src/client/websocket/handlers/GUILD_AUDIT_LOG_ENTRY_CREATE.js +1 -0
  54. package/src/client/websocket/handlers/GUILD_BAN_ADD.js +1 -0
  55. package/src/client/websocket/handlers/GUILD_BAN_REMOVE.js +1 -0
  56. package/src/client/websocket/handlers/GUILD_CREATE.js +2 -0
  57. package/src/client/websocket/handlers/GUILD_DELETE.js +2 -0
  58. package/src/client/websocket/handlers/GUILD_INTEGRATIONS_UPDATE.js +1 -0
  59. package/src/client/websocket/handlers/GUILD_MEMBERS_CHUNK.js +2 -0
  60. package/src/client/websocket/handlers/GUILD_MEMBER_ADD.js +1 -0
  61. package/src/client/websocket/handlers/GUILD_ROLE_UPDATE.js +1 -0
  62. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_CREATE.js +1 -0
  63. package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_UPDATE.js +1 -0
  64. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUNDS_UPDATE.js +1 -0
  65. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_CREATE.js +1 -0
  66. package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_UPDATE.js +1 -0
  67. package/src/client/websocket/handlers/INVITE_CREATE.js +1 -0
  68. package/src/client/websocket/handlers/INVITE_DELETE.js +1 -0
  69. package/src/client/websocket/handlers/MESSAGE_UPDATE.js +1 -0
  70. package/src/client/websocket/handlers/PRESENCE_UPDATE.js +3 -3
  71. package/src/client/websocket/handlers/READY.js +1 -0
  72. package/src/client/websocket/handlers/SOUNDBOARD_SOUNDS.js +1 -0
  73. package/src/client/websocket/handlers/SUBSCRIPTION_CREATE.js +1 -0
  74. package/src/client/websocket/handlers/SUBSCRIPTION_DELETE.js +1 -0
  75. package/src/client/websocket/handlers/SUBSCRIPTION_UPDATE.js +1 -0
  76. package/src/client/websocket/handlers/THREAD_DELETE.js +1 -0
  77. package/src/client/websocket/handlers/THREAD_LIST_SYNC.js +5 -2
  78. package/src/client/websocket/handlers/THREAD_MEMBER_UPDATE.js +1 -0
  79. package/src/client/websocket/handlers/THREAD_UPDATE.js +1 -0
  80. package/src/client/websocket/handlers/VOICE_CHANNEL_EFFECT_SEND.js +1 -0
  81. package/src/client/websocket/handlers/VOICE_STATE_UPDATE.js +1 -0
  82. package/src/client/websocket/handlers/WEBHOOKS_UPDATE.js +1 -0
  83. package/src/errors/DJSError.js +2 -0
  84. package/src/errors/ErrorCodes.js +38 -39
  85. package/src/errors/Messages.js +1 -1
  86. package/src/managers/ApplicationCommandManager.js +22 -7
  87. package/src/managers/ApplicationCommandPermissionsManager.js +55 -31
  88. package/src/managers/ApplicationEmojiManager.js +11 -1
  89. package/src/managers/AutoModerationRuleManager.js +22 -4
  90. package/src/managers/BaseManager.js +2 -0
  91. package/src/managers/CachedManager.js +5 -1
  92. package/src/managers/CategoryChannelChildManager.js +8 -2
  93. package/src/managers/ChannelManager.js +12 -3
  94. package/src/managers/DMMessageManager.js +2 -0
  95. package/src/managers/DataManager.js +8 -3
  96. package/src/managers/EntitlementManager.js +16 -5
  97. package/src/managers/GuildApplicationCommandManager.js +3 -0
  98. package/src/managers/GuildBanManager.js +17 -3
  99. package/src/managers/GuildChannelManager.js +41 -14
  100. package/src/managers/GuildEmojiManager.js +28 -8
  101. package/src/managers/GuildEmojiRoleManager.js +12 -2
  102. package/src/managers/GuildForumThreadManager.js +5 -1
  103. package/src/managers/GuildInviteManager.js +24 -10
  104. package/src/managers/GuildManager.js +34 -11
  105. package/src/managers/GuildMemberManager.js +56 -16
  106. package/src/managers/GuildMemberRoleManager.js +18 -3
  107. package/src/managers/GuildMessageManager.js +4 -1
  108. package/src/managers/GuildScheduledEventManager.js +26 -8
  109. package/src/managers/GuildSoundboardSoundManager.js +17 -5
  110. package/src/managers/GuildStickerManager.js +20 -6
  111. package/src/managers/GuildTextThreadManager.js +5 -1
  112. package/src/managers/MessageManager.js +28 -7
  113. package/src/managers/PartialGroupDMMessageManager.js +2 -0
  114. package/src/managers/PermissionOverwriteManager.js +14 -4
  115. package/src/managers/PollAnswerVoterManager.js +5 -1
  116. package/src/managers/PresenceManager.js +9 -4
  117. package/src/managers/ReactionManager.js +11 -4
  118. package/src/managers/ReactionUserManager.js +8 -1
  119. package/src/managers/RoleManager.js +29 -8
  120. package/src/managers/StageInstanceManager.js +14 -4
  121. package/src/managers/SubscriptionManager.js +6 -1
  122. package/src/managers/ThreadManager.js +21 -6
  123. package/src/managers/ThreadMemberManager.js +20 -5
  124. package/src/managers/UserManager.js +16 -6
  125. package/src/managers/VoiceStateManager.js +6 -1
  126. package/src/sharding/Shard.js +52 -17
  127. package/src/sharding/ShardClientUtil.js +45 -22
  128. package/src/sharding/ShardingManager.js +51 -15
  129. package/src/structures/ActionRow.js +4 -1
  130. package/src/structures/AnnouncementChannel.js +2 -0
  131. package/src/structures/AnonymousGuild.js +10 -0
  132. package/src/structures/ApplicationCommand.js +57 -14
  133. package/src/structures/ApplicationEmoji.js +20 -3
  134. package/src/structures/ApplicationRoleConnectionMetadata.js +6 -0
  135. package/src/structures/Attachment.js +15 -0
  136. package/src/structures/AttachmentBuilder.js +11 -0
  137. package/src/structures/AutoModerationActionExecution.js +15 -0
  138. package/src/structures/AutoModerationRule.js +44 -15
  139. package/src/structures/AutocompleteInteraction.js +11 -1
  140. package/src/structures/Base.js +2 -0
  141. package/src/structures/BaseChannel.js +19 -2
  142. package/src/structures/BaseGuild.js +16 -1
  143. package/src/structures/BaseGuildEmoji.js +10 -0
  144. package/src/structures/BaseGuildTextChannel.js +40 -11
  145. package/src/structures/BaseGuildVoiceChannel.js +39 -8
  146. package/src/structures/BaseInteraction.js +43 -3
  147. package/src/structures/BaseSelectMenuComponent.js +6 -0
  148. package/src/structures/ButtonComponent.js +7 -0
  149. package/src/structures/ButtonInteraction.js +1 -0
  150. package/src/structures/CategoryChannel.js +6 -1
  151. package/src/structures/ChannelSelectMenuComponent.js +2 -0
  152. package/src/structures/ChannelSelectMenuInteraction.js +3 -0
  153. package/src/structures/ChatInputCommandInteraction.js +4 -1
  154. package/src/structures/ClientApplication.js +38 -4
  155. package/src/structures/ClientPresence.js +6 -1
  156. package/src/structures/ClientUser.js +30 -13
  157. package/src/structures/CommandInteraction.js +23 -1
  158. package/src/structures/CommandInteractionOptionResolver.js +29 -0
  159. package/src/structures/Component.js +6 -0
  160. package/src/structures/ContainerComponent.js +7 -1
  161. package/src/structures/ContextMenuCommandInteraction.js +5 -1
  162. package/src/structures/DMChannel.js +21 -4
  163. package/src/structures/DirectoryChannel.js +4 -0
  164. package/src/structures/Embed.js +17 -0
  165. package/src/structures/Emoji.js +9 -0
  166. package/src/structures/Entitlement.js +21 -1
  167. package/src/structures/FileComponent.js +4 -0
  168. package/src/structures/ForumChannel.js +4 -1
  169. package/src/structures/Guild.js +154 -40
  170. package/src/structures/GuildAuditLogs.js +7 -1
  171. package/src/structures/GuildAuditLogsEntry.js +67 -43
  172. package/src/structures/GuildBan.js +7 -1
  173. package/src/structures/GuildChannel.js +34 -6
  174. package/src/structures/GuildEmoji.js +16 -4
  175. package/src/structures/GuildMember.js +61 -11
  176. package/src/structures/GuildOnboarding.js +7 -0
  177. package/src/structures/GuildOnboardingPrompt.js +10 -0
  178. package/src/structures/GuildOnboardingPromptOption.js +10 -0
  179. package/src/structures/GuildPreview.js +23 -3
  180. package/src/structures/GuildPreviewEmoji.js +3 -0
  181. package/src/structures/GuildScheduledEvent.js +57 -12
  182. package/src/structures/GuildTemplate.js +33 -10
  183. package/src/structures/Integration.js +27 -4
  184. package/src/structures/IntegrationApplication.js +7 -0
  185. package/src/structures/InteractionCallback.js +9 -0
  186. package/src/structures/InteractionCallbackResource.js +5 -0
  187. package/src/structures/InteractionCallbackResponse.js +3 -0
  188. package/src/structures/InteractionCollector.js +18 -1
  189. package/src/structures/InteractionWebhook.js +12 -4
  190. package/src/structures/Invite.js +31 -3
  191. package/src/structures/InviteGuild.js +3 -1
  192. package/src/structures/MediaChannel.js +1 -0
  193. package/src/structures/MediaGalleryComponent.js +3 -0
  194. package/src/structures/MediaGalleryItem.js +5 -0
  195. package/src/structures/MentionableSelectMenuComponent.js +1 -0
  196. package/src/structures/MentionableSelectMenuInteraction.js +6 -1
  197. package/src/structures/Message.js +113 -45
  198. package/src/structures/MessageCollector.js +14 -3
  199. package/src/structures/MessageComponentInteraction.js +29 -8
  200. package/src/structures/MessageContextMenuCommandInteraction.js +2 -0
  201. package/src/structures/MessageMentions.js +28 -2
  202. package/src/structures/MessagePayload.js +16 -13
  203. package/src/structures/MessageReaction.js +25 -6
  204. package/src/structures/ModalSubmitFields.js +5 -1
  205. package/src/structures/ModalSubmitInteraction.js +20 -1
  206. package/src/structures/OAuth2Guild.js +4 -1
  207. package/src/structures/PartialGroupDMChannel.js +18 -3
  208. package/src/structures/PermissionOverwrites.js +20 -5
  209. package/src/structures/Poll.js +17 -1
  210. package/src/structures/PollAnswer.js +14 -3
  211. package/src/structures/Presence.js +55 -11
  212. package/src/structures/PrimaryEntryPointCommandInteraction.js +1 -0
  213. package/src/structures/ReactionCollector.js +19 -2
  214. package/src/structures/ReactionEmoji.js +3 -1
  215. package/src/structures/Role.js +52 -10
  216. package/src/structures/RoleSelectMenuComponent.js +1 -0
  217. package/src/structures/RoleSelectMenuInteraction.js +3 -0
  218. package/src/structures/SKU.js +8 -1
  219. package/src/structures/SectionComponent.js +5 -1
  220. package/src/structures/SeparatorComponent.js +3 -0
  221. package/src/structures/SoundboardSound.js +17 -1
  222. package/src/structures/StageChannel.js +11 -2
  223. package/src/structures/StageInstance.js +18 -4
  224. package/src/structures/Sticker.js +26 -2
  225. package/src/structures/StickerPack.js +12 -0
  226. package/src/structures/StringSelectMenuComponent.js +2 -0
  227. package/src/structures/StringSelectMenuInteraction.js +2 -0
  228. package/src/structures/Subscription.js +14 -0
  229. package/src/structures/Team.js +12 -0
  230. package/src/structures/TeamMember.js +7 -0
  231. package/src/structures/TextChannel.js +4 -1
  232. package/src/structures/TextDisplayComponent.js +2 -0
  233. package/src/structures/TextInputComponent.js +3 -0
  234. package/src/structures/ThreadChannel.js +75 -15
  235. package/src/structures/ThreadMember.js +13 -1
  236. package/src/structures/ThreadOnlyChannel.js +32 -11
  237. package/src/structures/ThumbnailComponent.js +5 -0
  238. package/src/structures/Typing.js +8 -0
  239. package/src/structures/UnfurledMediaItem.js +3 -0
  240. package/src/structures/User.js +35 -4
  241. package/src/structures/UserContextMenuCommandInteraction.js +3 -0
  242. package/src/structures/UserSelectMenuComponent.js +1 -0
  243. package/src/structures/UserSelectMenuInteraction.js +5 -1
  244. package/src/structures/VoiceChannel.js +9 -2
  245. package/src/structures/VoiceChannelEffect.js +10 -0
  246. package/src/structures/VoiceRegion.js +5 -0
  247. package/src/structures/VoiceState.js +34 -8
  248. package/src/structures/Webhook.js +48 -12
  249. package/src/structures/WelcomeChannel.js +7 -0
  250. package/src/structures/WelcomeScreen.js +5 -0
  251. package/src/structures/Widget.js +10 -0
  252. package/src/structures/WidgetMember.js +15 -0
  253. package/src/structures/interfaces/Application.js +15 -0
  254. package/src/structures/interfaces/Collector.js +39 -6
  255. package/src/structures/interfaces/InteractionResponses.js +21 -1
  256. package/src/structures/interfaces/TextBasedChannel.js +37 -8
  257. package/src/util/APITypes.js +1 -1
  258. package/src/util/ActivityFlagsBitField.js +3 -0
  259. package/src/util/ApplicationFlagsBitField.js +9 -4
  260. package/src/util/AttachmentFlagsBitField.js +3 -0
  261. package/src/util/BitField.js +23 -4
  262. package/src/util/ChannelFlagsBitField.js +9 -4
  263. package/src/util/Channels.js +17 -1
  264. package/src/util/Components.js +5 -0
  265. package/src/util/Constants.js +91 -73
  266. package/src/util/DataResolver.js +21 -10
  267. package/src/util/Enums.js +1 -0
  268. package/src/util/GuildMemberFlagsBitField.js +9 -4
  269. package/src/util/IntentsBitField.js +8 -4
  270. package/src/util/LimitedCollection.js +11 -4
  271. package/src/util/MessageFlagsBitField.js +9 -4
  272. package/src/util/Options.js +18 -5
  273. package/src/util/Partials.js +1 -0
  274. package/src/util/PermissionsBitField.js +19 -6
  275. package/src/util/RoleFlagsBitField.js +3 -0
  276. package/src/util/SKUFlagsBitField.js +3 -0
  277. package/src/util/Status.js +3 -3
  278. package/src/util/Sweepers.js +56 -10
  279. package/src/util/SystemChannelFlagsBitField.js +9 -4
  280. package/src/util/ThreadMemberFlagsBitField.js +4 -0
  281. package/src/util/Transformers.js +5 -0
  282. package/src/util/UserFlagsBitField.js +4 -0
  283. package/src/util/Util.js +72 -23
  284. package/typings/index.d.mts +972 -976
  285. package/typings/index.d.ts +972 -976
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "discord.js",
4
- "version": "15.0.0-dev.1748650424-ef2c1bfa7",
4
+ "version": "15.0.0-dev.1749297897-970871720",
5
5
  "description": "A powerful library for interacting with the Discord API",
6
6
  "main": "./src/index.js",
7
7
  "types": "./typings/index.d.ts",
@@ -63,19 +63,17 @@
63
63
  "undici": "7.8.0",
64
64
  "@discordjs/builders": "^1.11.1",
65
65
  "@discordjs/collection": "^2.1.1",
66
- "@discordjs/rest": "^2.5.0",
67
66
  "@discordjs/formatters": "^0.6.1",
68
- "@discordjs/util": "^1.1.1",
69
- "@discordjs/ws": "^2.0.2"
67
+ "@discordjs/rest": "^2.5.0",
68
+ "@discordjs/ws": "^2.0.2",
69
+ "@discordjs/util": "^1.1.1"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@favware/cliff-jumper": "^4.1.0",
73
73
  "@types/node": "^22.15.2",
74
- "@typescript-eslint/eslint-plugin": "^8.29.0",
75
- "@typescript-eslint/parser": "^8.29.0",
76
74
  "cross-env": "^7.0.3",
77
- "dtslint": "4.2.1",
78
75
  "eslint": "^9.25.1",
76
+ "eslint-config-neon": "^0.2.7",
79
77
  "eslint-formatter-compact": "^8.40.0",
80
78
  "eslint-formatter-pretty": "^5.0.0",
81
79
  "eslint-plugin-import": "^2.31.0",
@@ -83,7 +81,6 @@
83
81
  "jest": "29.7.0",
84
82
  "prettier": "^3.5.3",
85
83
  "tsd": "^0.31.2",
86
- "tslint": "6.1.3",
87
84
  "turbo": "^2.5.2",
88
85
  "typescript": "~5.8.3",
89
86
  "@discordjs/api-extractor": "^7.52.7",
@@ -99,8 +96,8 @@
99
96
  "scripts": {
100
97
  "test": "pnpm run docs:test && pnpm run test:typescript",
101
98
  "test:typescript": "tsc --noEmit && tsd",
102
- "lint": "prettier --check . && tslint typings/index.d.ts && cross-env ESLINT_USE_FLAT_CONFIG=false eslint --format=pretty src typings",
103
- "format": "prettier --write . && cross-env ESLINT_USE_FLAT_CONFIG=false eslint --fix --format=pretty src",
99
+ "lint": "prettier --check . && cross-env TIMING=1 eslint --format=pretty scripts src typings",
100
+ "format": "prettier --write . && cross-env TIMING=1 eslint --fix --format=pretty scripts src typings",
104
101
  "fmt": "pnpm run format",
105
102
  "docs": "docgen -i \"./src/*.js\" \"./src/**/*.js\" -c ./docs/index.json -r ../../ -o ./docs/docs.json && pnpm run docs:new",
106
103
  "docs:test": "docgen -i \"./src/*.js\" \"./src/**/*.js\" -c ./docs/index.json -r ../../",
@@ -10,6 +10,7 @@ const { flatten } = require('../util/Util.js');
10
10
 
11
11
  /**
12
12
  * The base class for all clients.
13
+ *
13
14
  * @extends {AsyncEventEmitter}
14
15
  */
15
16
  class BaseClient extends AsyncEventEmitter {
@@ -23,6 +24,7 @@ class BaseClient extends AsyncEventEmitter {
23
24
  const defaultOptions = Options.createDefault();
24
25
  /**
25
26
  * The options the client was instantiated with
27
+ *
26
28
  * @type {ClientOptions}
27
29
  */
28
30
  this.options = {
@@ -51,6 +53,7 @@ class BaseClient extends AsyncEventEmitter {
51
53
 
52
54
  /**
53
55
  * The REST manager of the client
56
+ *
54
57
  * @type {REST}
55
58
  */
56
59
  this.rest = new REST(this.options.rest);
@@ -60,6 +63,7 @@ class BaseClient extends AsyncEventEmitter {
60
63
 
61
64
  /**
62
65
  * Destroys all assets used by the base client.
66
+ *
63
67
  * @returns {void}
64
68
  */
65
69
  destroy() {
@@ -69,6 +73,7 @@ class BaseClient extends AsyncEventEmitter {
69
73
 
70
74
  /**
71
75
  * Options used for deleting a webhook.
76
+ *
72
77
  * @typedef {Object} WebhookDeleteOptions
73
78
  * @property {string} [token] Token of the webhook
74
79
  * @property {string} [reason] The reason for deleting the webhook
@@ -76,6 +81,7 @@ class BaseClient extends AsyncEventEmitter {
76
81
 
77
82
  /**
78
83
  * Deletes a webhook.
84
+ *
79
85
  * @param {Snowflake} id The webhook's id
80
86
  * @param {WebhookDeleteOptions} [options] Options for deleting the webhook
81
87
  * @returns {Promise<void>}
@@ -86,6 +92,7 @@ class BaseClient extends AsyncEventEmitter {
86
92
 
87
93
  /**
88
94
  * Increments max listeners by one, if they are not zero.
95
+ *
89
96
  * @private
90
97
  */
91
98
  incrementMaxListeners() {
@@ -97,6 +104,7 @@ class BaseClient extends AsyncEventEmitter {
97
104
 
98
105
  /**
99
106
  * Decrements max listeners by one, if they are not zero.
107
+ *
100
108
  * @private
101
109
  */
102
110
  decrementMaxListeners() {
@@ -6,10 +6,6 @@ const { Collection } = require('@discordjs/collection');
6
6
  const { makeURLSearchParams } = require('@discordjs/rest');
7
7
  const { WebSocketManager, WebSocketShardEvents, WebSocketShardStatus } = require('@discordjs/ws');
8
8
  const { GatewayDispatchEvents, GatewayIntentBits, OAuth2Scopes, Routes } = require('discord-api-types/v10');
9
- const { BaseClient } = require('./BaseClient.js');
10
- const { ActionsManager } = require('./actions/ActionsManager.js');
11
- const { ClientVoiceManager } = require('./voice/ClientVoiceManager.js');
12
- const { PacketHandlers } = require('./websocket/handlers/index.js');
13
9
  const { DiscordjsError, DiscordjsTypeError, ErrorCodes } = require('../errors/index.js');
14
10
  const { ChannelManager } = require('../managers/ChannelManager.js');
15
11
  const { GuildManager } = require('../managers/GuildManager.js');
@@ -32,6 +28,10 @@ const { Options } = require('../util/Options.js');
32
28
  const { PermissionsBitField } = require('../util/PermissionsBitField.js');
33
29
  const { Status } = require('../util/Status.js');
34
30
  const { Sweepers } = require('../util/Sweepers.js');
31
+ const { BaseClient } = require('./BaseClient.js');
32
+ const { ActionsManager } = require('./actions/ActionsManager.js');
33
+ const { ClientVoiceManager } = require('./voice/ClientVoiceManager.js');
34
+ const { PacketHandlers } = require('./websocket/handlers/index.js');
35
35
 
36
36
  const WaitingForGuildEvents = [GatewayDispatchEvents.GuildCreate, GatewayDispatchEvents.GuildDelete];
37
37
  const BeforeReadyWhitelist = [
@@ -46,6 +46,7 @@ const BeforeReadyWhitelist = [
46
46
 
47
47
  /**
48
48
  * The main hub for interacting with the Discord API, and the starting point for any bot.
49
+ *
49
50
  * @extends {BaseClient}
50
51
  */
51
52
  class Client extends BaseClient {
@@ -69,6 +70,7 @@ class Client extends BaseClient {
69
70
 
70
71
  /**
71
72
  * The presence of the Client
73
+ *
72
74
  * @private
73
75
  * @type {ClientPresence}
74
76
  */
@@ -78,6 +80,7 @@ class Client extends BaseClient {
78
80
 
79
81
  /**
80
82
  * The current status of this Client
83
+ *
81
84
  * @type {Status}
82
85
  * @private
83
86
  */
@@ -85,6 +88,7 @@ class Client extends BaseClient {
85
88
 
86
89
  /**
87
90
  * A set of guild ids this Client expects to receive
91
+ *
88
92
  * @name Client#expectedGuilds
89
93
  * @type {Set<string>}
90
94
  * @private
@@ -93,6 +97,7 @@ class Client extends BaseClient {
93
97
 
94
98
  /**
95
99
  * The ready timeout
100
+ *
96
101
  * @name Client#readyTimeout
97
102
  * @type {?NodeJS.Timeout}
98
103
  * @private
@@ -101,6 +106,7 @@ class Client extends BaseClient {
101
106
 
102
107
  /**
103
108
  * The action manager of the client
109
+ *
104
110
  * @type {ActionsManager}
105
111
  * @private
106
112
  */
@@ -108,6 +114,7 @@ class Client extends BaseClient {
108
114
 
109
115
  /**
110
116
  * The user manager of this client
117
+ *
111
118
  * @type {UserManager}
112
119
  */
113
120
  this.users = new UserManager(this);
@@ -115,6 +122,7 @@ class Client extends BaseClient {
115
122
  /**
116
123
  * A manager of all the guilds the client is currently handling -
117
124
  * as long as sharding isn't being used, this will be *every* guild the bot is a member of
125
+ *
118
126
  * @type {GuildManager}
119
127
  */
120
128
  this.guilds = new GuildManager(this);
@@ -124,12 +132,14 @@ class Client extends BaseClient {
124
132
  * as long as sharding isn't being used, this will be *every* channel in *every* guild the bot
125
133
  * is a member of. Note that DM channels will not be initially cached, and thus not be present
126
134
  * in the Manager without their explicit fetching or use.
135
+ *
127
136
  * @type {ChannelManager}
128
137
  */
129
138
  this.channels = new ChannelManager(this);
130
139
 
131
140
  /**
132
141
  * The sweeping functions and their intervals used to periodically sweep caches
142
+ *
133
143
  * @type {Sweepers}
134
144
  */
135
145
  this.sweepers = new Sweepers(this, this.options.sweepers);
@@ -140,6 +150,7 @@ class Client extends BaseClient {
140
150
  * Authorization token for the logged in bot.
141
151
  * If present, this defaults to `process.env.DISCORD_TOKEN` when instantiating the client
142
152
  * <warn>This should be kept private at all times.</warn>
153
+ *
143
154
  * @type {?string}
144
155
  */
145
156
  this.token = process.env.DISCORD_TOKEN;
@@ -159,12 +170,14 @@ class Client extends BaseClient {
159
170
 
160
171
  /**
161
172
  * The WebSocket manager of the client
173
+ *
162
174
  * @type {WebSocketManager}
163
175
  */
164
176
  this.ws = new WebSocketManager(wsOptions);
165
177
 
166
178
  /**
167
179
  * Shard helpers for the client (only if the process was spawned from a {@link ShardingManager})
180
+ *
168
181
  * @type {?ShardClientUtil}
169
182
  */
170
183
  this.shard = process.env.SHARDING_MANAGER
@@ -173,42 +186,49 @@ class Client extends BaseClient {
173
186
 
174
187
  /**
175
188
  * The voice manager of the client
189
+ *
176
190
  * @type {ClientVoiceManager}
177
191
  */
178
192
  this.voice = new ClientVoiceManager(this);
179
193
 
180
194
  /**
181
195
  * User that the client is logged in as
196
+ *
182
197
  * @type {?ClientUser}
183
198
  */
184
199
  this.user = null;
185
200
 
186
201
  /**
187
202
  * The application of this bot
203
+ *
188
204
  * @type {?ClientApplication}
189
205
  */
190
206
  this.application = null;
191
207
 
192
208
  /**
193
209
  * The latencies of the WebSocketShard connections
210
+ *
194
211
  * @type {Collection<number, number>}
195
212
  */
196
213
  this.pings = new Collection();
197
214
 
198
215
  /**
199
216
  * The last time a ping was sent (a timestamp) for each WebSocketShard connection
217
+ *
200
218
  * @type {Collection<number, number>}
201
219
  */
202
220
  this.lastPingTimestamps = new Collection();
203
221
 
204
222
  /**
205
223
  * Timestamp of the time the client was last {@link Status.Ready} at
224
+ *
206
225
  * @type {?number}
207
226
  */
208
227
  this.readyTimestamp = null;
209
228
 
210
229
  /**
211
230
  * An array of queued events before this Client became ready
231
+ *
212
232
  * @type {Object[]}
213
233
  * @private
214
234
  * @name Client#incomingPacketQueue
@@ -221,6 +241,7 @@ class Client extends BaseClient {
221
241
  /**
222
242
  * Time at which the client was last regarded as being in the {@link Status.Ready} state
223
243
  * (each time the client disconnects and successfully reconnects, this will be overwritten)
244
+ *
224
245
  * @type {?Date}
225
246
  * @readonly
226
247
  */
@@ -230,6 +251,7 @@ class Client extends BaseClient {
230
251
 
231
252
  /**
232
253
  * How long it has been since the client last entered the {@link Status.Ready} state in milliseconds
254
+ *
233
255
  * @type {?number}
234
256
  * @readonly
235
257
  */
@@ -239,6 +261,7 @@ class Client extends BaseClient {
239
261
 
240
262
  /**
241
263
  * Logs the client in, establishing a WebSocket connection to Discord.
264
+ *
242
265
  * @param {string} [token=this.token] Token of the account to log in with
243
266
  * @returns {Promise<string>} Token of the account used
244
267
  * @example
@@ -246,7 +269,7 @@ class Client extends BaseClient {
246
269
  */
247
270
  async login(token = this.token) {
248
271
  if (!token || typeof token !== 'string') throw new DiscordjsError(ErrorCodes.TokenInvalid);
249
- this.token = token.replace(/^(Bot|Bearer)\s*/i, '');
272
+ this.token = token.replace(/^bot\s*/i, '');
250
273
 
251
274
  this.rest.setToken(this.token);
252
275
 
@@ -266,6 +289,7 @@ class Client extends BaseClient {
266
289
 
267
290
  /**
268
291
  * Checks if the client can be marked as ready
292
+ *
269
293
  * @private
270
294
  */
271
295
  async _checkReady() {
@@ -274,6 +298,7 @@ class Client extends BaseClient {
274
298
  clearTimeout(this.readyTimeout);
275
299
  this.readyTimeout = null;
276
300
  }
301
+
277
302
  // Step 1. If we don't have any other guilds pending, we are ready
278
303
  if (
279
304
  !this.expectedGuilds.size &&
@@ -284,6 +309,7 @@ class Client extends BaseClient {
284
309
  this._triggerClientReady();
285
310
  return;
286
311
  }
312
+
287
313
  const hasGuildsIntent = this.options.intents.has(GatewayIntentBits.Guilds);
288
314
  // Step 2. Create a timeout that will mark the client as ready if there are still unavailable guilds
289
315
  // * The timeout is 15 seconds by default
@@ -311,6 +337,7 @@ class Client extends BaseClient {
311
337
 
312
338
  /**
313
339
  * Attaches event handlers to the WebSocketShardManager from `@discordjs/ws`.
340
+ *
314
341
  * @private
315
342
  */
316
343
  _attachEvents() {
@@ -319,12 +346,13 @@ class Client extends BaseClient {
319
346
  );
320
347
  this.ws.on(WebSocketShardEvents.Dispatch, this._handlePacket.bind(this));
321
348
 
322
- this.ws.on(WebSocketShardEvents.Ready, data => {
349
+ this.ws.on(WebSocketShardEvents.Ready, async data => {
323
350
  for (const guild of data.guilds) {
324
351
  this.expectedGuilds.add(guild.id);
325
352
  }
353
+
326
354
  this.status = Status.WaitingForGuilds;
327
- this._checkReady();
355
+ await this._checkReady();
328
356
  });
329
357
 
330
358
  this.ws.on(WebSocketShardEvents.HeartbeatComplete, ({ heartbeatAt, latency }, shardId) => {
@@ -336,18 +364,19 @@ class Client extends BaseClient {
336
364
 
337
365
  /**
338
366
  * Processes a packet and queues it if this WebSocketManager is not ready.
367
+ *
339
368
  * @param {GatewayDispatchPayload} packet The packet to be handled
340
369
  * @param {number} shardId The shardId that received this packet
341
370
  * @private
342
371
  */
343
- _handlePacket(packet, shardId) {
372
+ async _handlePacket(packet, shardId) {
344
373
  if (this.status !== Status.Ready && !BeforeReadyWhitelist.includes(packet.t)) {
345
374
  this.incomingPacketQueue.push({ packet, shardId });
346
375
  } else {
347
376
  if (this.incomingPacketQueue.length) {
348
377
  const item = this.incomingPacketQueue.shift();
349
- setImmediate(() => {
350
- this._handlePacket(item.packet, item.shardId);
378
+ setImmediate(async () => {
379
+ await this._handlePacket(item.packet, item.shardId);
351
380
  }).unref();
352
381
  }
353
382
 
@@ -357,13 +386,14 @@ class Client extends BaseClient {
357
386
 
358
387
  if (this.status === Status.WaitingForGuilds && WaitingForGuildEvents.includes(packet.t)) {
359
388
  this.expectedGuilds.delete(packet.d.id);
360
- this._checkReady();
389
+ await this._checkReady();
361
390
  }
362
391
  }
363
392
  }
364
393
 
365
394
  /**
366
395
  * Broadcasts a packet to every shard of this client handles.
396
+ *
367
397
  * @param {Object} packet The packet to send
368
398
  * @private
369
399
  */
@@ -374,6 +404,7 @@ class Client extends BaseClient {
374
404
 
375
405
  /**
376
406
  * Causes the client to be marked as ready and emits the ready event.
407
+ *
377
408
  * @private
378
409
  */
379
410
  _triggerClientReady() {
@@ -383,6 +414,7 @@ class Client extends BaseClient {
383
414
 
384
415
  /**
385
416
  * Emitted when the client becomes ready to start working.
417
+ *
386
418
  * @event Client#clientReady
387
419
  * @param {Client} client The client
388
420
  */
@@ -392,6 +424,7 @@ class Client extends BaseClient {
392
424
  /**
393
425
  * Returns whether the client has logged in, indicative of being able to access
394
426
  * properties such as `user` and `application`.
427
+ *
395
428
  * @returns {boolean}
396
429
  */
397
430
  isReady() {
@@ -400,6 +433,7 @@ class Client extends BaseClient {
400
433
 
401
434
  /**
402
435
  * The average ping of all WebSocketShards
436
+ *
403
437
  * @type {?number}
404
438
  * @readonly
405
439
  */
@@ -409,6 +443,7 @@ class Client extends BaseClient {
409
443
 
410
444
  /**
411
445
  * Logs out, terminates the connection to Discord, and destroys the client.
446
+ *
412
447
  * @returns {Promise<void>}
413
448
  */
414
449
  async destroy() {
@@ -422,6 +457,7 @@ class Client extends BaseClient {
422
457
 
423
458
  /**
424
459
  * Options used when fetching an invite from Discord.
460
+ *
425
461
  * @typedef {Object} ClientFetchInviteOptions
426
462
  * @property {Snowflake} [guildScheduledEventId] The id of the guild scheduled event to include with
427
463
  * the invite
@@ -429,6 +465,7 @@ class Client extends BaseClient {
429
465
 
430
466
  /**
431
467
  * Obtains an invite from Discord.
468
+ *
432
469
  * @param {InviteResolvable} invite Invite code or URL
433
470
  * @param {ClientFetchInviteOptions} [options] Options for fetching the invite
434
471
  * @returns {Promise<Invite>}
@@ -449,6 +486,7 @@ class Client extends BaseClient {
449
486
 
450
487
  /**
451
488
  * Obtains a template from Discord.
489
+ *
452
490
  * @param {GuildTemplateResolvable} template Template code or URL
453
491
  * @returns {Promise<GuildTemplate>}
454
492
  * @example
@@ -464,6 +502,7 @@ class Client extends BaseClient {
464
502
 
465
503
  /**
466
504
  * Obtains a webhook from Discord.
505
+ *
467
506
  * @param {Snowflake} id The webhook's id
468
507
  * @param {string} [token] Token for the webhook
469
508
  * @returns {Promise<Webhook>}
@@ -479,6 +518,7 @@ class Client extends BaseClient {
479
518
 
480
519
  /**
481
520
  * Obtains the available voice regions from Discord.
521
+ *
482
522
  * @returns {Promise<Collection<string, VoiceRegion>>}
483
523
  * @example
484
524
  * client.fetchVoiceRegions()
@@ -494,6 +534,7 @@ class Client extends BaseClient {
494
534
 
495
535
  /**
496
536
  * Obtains a sticker from Discord.
537
+ *
497
538
  * @param {Snowflake} id The sticker's id
498
539
  * @returns {Promise<Sticker>}
499
540
  * @example
@@ -508,12 +549,14 @@ class Client extends BaseClient {
508
549
 
509
550
  /**
510
551
  * Options for fetching sticker packs.
552
+ *
511
553
  * @typedef {Object} StickerPackFetchOptions
512
554
  * @property {Snowflake} [packId] The id of the sticker pack to fetch
513
555
  */
514
556
 
515
557
  /**
516
558
  * Obtains the list of available sticker packs.
559
+ *
517
560
  * @param {StickerPackFetchOptions} [options={}] Options for fetching sticker packs
518
561
  * @returns {Promise<Collection<Snowflake, StickerPack>|StickerPack>}
519
562
  * A collection of sticker packs, or a single sticker pack if a packId was provided
@@ -528,8 +571,8 @@ class Client extends BaseClient {
528
571
  */
529
572
  async fetchStickerPacks({ packId } = {}) {
530
573
  if (packId) {
531
- const data = await this.rest.get(Routes.stickerPack(packId));
532
- return new StickerPack(this, data);
574
+ const innerData = await this.rest.get(Routes.stickerPack(packId));
575
+ return new StickerPack(this, innerData);
533
576
  }
534
577
 
535
578
  const data = await this.rest.get(Routes.stickerPacks());
@@ -538,6 +581,7 @@ class Client extends BaseClient {
538
581
 
539
582
  /**
540
583
  * Obtains the list of default soundboard sounds.
584
+ *
541
585
  * @returns {Promise<Collection<string, SoundboardSound>>}
542
586
  * @example
543
587
  * client.fetchDefaultSoundboardSounds()
@@ -551,6 +595,7 @@ class Client extends BaseClient {
551
595
 
552
596
  /**
553
597
  * Obtains a guild preview from Discord, available for all guilds the bot is in and all Discoverable guilds.
598
+ *
554
599
  * @param {GuildResolvable} guild The guild to fetch the preview for
555
600
  * @returns {Promise<GuildPreview>}
556
601
  */
@@ -563,6 +608,7 @@ class Client extends BaseClient {
563
608
 
564
609
  /**
565
610
  * Obtains the widget data of a guild from Discord, available for guilds with the widget enabled.
611
+ *
566
612
  * @param {GuildResolvable} guild The guild to fetch the widget data for
567
613
  * @returns {Promise<Widget>}
568
614
  */
@@ -575,6 +621,7 @@ class Client extends BaseClient {
575
621
 
576
622
  /**
577
623
  * Options for {@link Client#generateInvite}.
624
+ *
578
625
  * @typedef {Object} InviteGenerationOptions
579
626
  * @property {OAuth2Scopes[]} scopes Scopes that should be requested
580
627
  * @property {PermissionResolvable} [permissions] Permissions to request
@@ -584,6 +631,7 @@ class Client extends BaseClient {
584
631
 
585
632
  /**
586
633
  * Generates a link that can be used to invite the bot to a guild.
634
+ *
587
635
  * @param {InviteGenerationOptions} [options={}] Options for the invite
588
636
  * @returns {string}
589
637
  * @example
@@ -610,15 +658,19 @@ class Client extends BaseClient {
610
658
  if (scopes === undefined) {
611
659
  throw new DiscordjsTypeError(ErrorCodes.InvalidMissingScopes);
612
660
  }
661
+
613
662
  if (!Array.isArray(scopes)) {
614
663
  throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'scopes', 'Array of Invite Scopes', true);
615
664
  }
665
+
616
666
  if (!scopes.some(scope => [OAuth2Scopes.Bot, OAuth2Scopes.ApplicationsCommands].includes(scope))) {
617
667
  throw new DiscordjsTypeError(ErrorCodes.InvalidMissingScopes);
618
668
  }
669
+
619
670
  if (!scopes.includes(OAuth2Scopes.Bot) && options.permissions) {
620
671
  throw new DiscordjsTypeError(ErrorCodes.InvalidScopesWithPermissions);
621
672
  }
673
+
622
674
  const validScopes = Object.values(OAuth2Scopes);
623
675
  const invalidScope = scopes.find(scope => !validScopes.includes(scope));
624
676
  if (invalidScope) {
@@ -654,6 +706,7 @@ class Client extends BaseClient {
654
706
 
655
707
  /**
656
708
  * Partially censored client token for debug logging purposes.
709
+ *
657
710
  * @type {?string}
658
711
  * @readonly
659
712
  * @private
@@ -663,23 +716,26 @@ class Client extends BaseClient {
663
716
 
664
717
  return this.token
665
718
  .split('.')
666
- .map((val, i) => (i > 1 ? val.replace(/./g, '*') : val))
719
+ .map((val, index) => (index > 1 ? val.replaceAll(/./g, '*') : val))
667
720
  .join('.');
668
721
  }
669
722
 
670
723
  /**
671
724
  * Calls {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/eval} on a script
672
725
  * with the client as `this`.
726
+ *
673
727
  * @param {string} script Script to eval
674
728
  * @returns {*}
675
729
  * @private
676
730
  */
677
731
  _eval(script) {
732
+ // eslint-disable-next-line no-eval
678
733
  return eval(script);
679
734
  }
680
735
 
681
736
  /**
682
737
  * Validates the client options.
738
+ *
683
739
  * @param {ClientOptions} [options=this.options] Options to validate
684
740
  * @private
685
741
  */
@@ -689,30 +745,38 @@ class Client extends BaseClient {
689
745
  } else {
690
746
  options.intents = new IntentsBitField(options.intents ?? options.ws.intents).freeze();
691
747
  }
748
+
692
749
  if (typeof options.sweepers !== 'object' || options.sweepers === null) {
693
750
  throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'sweepers', 'an object');
694
751
  }
752
+
695
753
  if (!Array.isArray(options.partials)) {
696
754
  throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'partials', 'an Array');
697
755
  }
698
- if (typeof options.waitGuildTimeout !== 'number' || isNaN(options.waitGuildTimeout)) {
756
+
757
+ if (typeof options.waitGuildTimeout !== 'number' || Number.isNaN(options.waitGuildTimeout)) {
699
758
  throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'waitGuildTimeout', 'a number');
700
759
  }
760
+
701
761
  if (typeof options.failIfNotExists !== 'boolean') {
702
762
  throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'failIfNotExists', 'a boolean');
703
763
  }
764
+
704
765
  if (typeof options.enforceNonce !== 'boolean') {
705
766
  throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'enforceNonce', 'a boolean');
706
767
  }
768
+
707
769
  if (
708
770
  (typeof options.allowedMentions !== 'object' && options.allowedMentions !== undefined) ||
709
771
  options.allowedMentions === null
710
772
  ) {
711
773
  throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'allowedMentions', 'an object');
712
774
  }
775
+
713
776
  if (typeof options.ws !== 'object' || options.ws === null) {
714
777
  throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'ws', 'an object');
715
778
  }
779
+
716
780
  if (
717
781
  (typeof options.presence !== 'object' || options.presence === null) &&
718
782
  options.ws.initialPresence === undefined
@@ -721,9 +785,11 @@ class Client extends BaseClient {
721
785
  } else {
722
786
  options.ws.initialPresence = options.ws.initialPresence ?? this.presence._parse(this.options.presence);
723
787
  }
788
+
724
789
  if (typeof options.rest !== 'object' || options.rest === null) {
725
790
  throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'rest', 'an object');
726
791
  }
792
+
727
793
  if (typeof options.jsonTransformer !== 'function') {
728
794
  throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'jsonTransformer', 'a function');
729
795
  }
@@ -754,17 +820,20 @@ exports.Client = Client;
754
820
  * 000000111011000111100001101001000101000000 00001 00000 000000000000
755
821
  * number of milliseconds since Discord epoch worker pid increment
756
822
  * ```
823
+ *
757
824
  * @typedef {string} Snowflake
758
825
  */
759
826
 
760
827
  /**
761
828
  * Emitted for general debugging information.
829
+ *
762
830
  * @event Client#debug
763
831
  * @param {string} info The debug information
764
832
  */
765
833
 
766
834
  /**
767
835
  * Emitted for general warnings.
836
+ *
768
837
  * @event Client#warn
769
838
  * @param {string} info The warning
770
839
  */