lolka.js 0.1.3 → 0.2.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.
- package/README.md +6 -6
- package/package.json +21 -52
- package/src/client/BaseClient.js +120 -0
- package/src/client/Client.js +147 -446
- package/src/client/WebhookClient.js +103 -0
- package/src/client/actions/Action.js +3 -4
- package/src/client/actions/ActionsManager.js +65 -55
- package/src/client/actions/ApplicationCommandPermissionsUpdate.js +34 -0
- package/src/client/actions/AutoModerationActionExecution.js +26 -0
- package/src/client/actions/AutoModerationRuleCreate.js +27 -0
- package/src/client/actions/AutoModerationRuleDelete.js +31 -0
- package/src/client/actions/AutoModerationRuleUpdate.js +29 -0
- package/src/client/actions/ChannelCreate.js +3 -5
- package/src/client/actions/ChannelDelete.js +3 -4
- package/src/client/actions/ChannelUpdate.js +3 -3
- package/src/client/actions/EntitlementCreate.js +23 -0
- package/src/client/actions/EntitlementDelete.js +27 -0
- package/src/client/actions/EntitlementUpdate.js +25 -0
- package/src/client/actions/GuildAuditLogEntryCreate.js +29 -0
- package/src/client/actions/GuildBanAdd.js +20 -0
- package/src/client/actions/GuildBanRemove.js +25 -0
- package/src/client/actions/GuildChannelsPositionUpdate.js +3 -3
- package/src/client/actions/GuildDelete.js +44 -0
- package/src/client/actions/GuildEmojiCreate.js +3 -4
- package/src/client/actions/GuildEmojiDelete.js +3 -4
- package/src/client/actions/GuildEmojiUpdate.js +3 -4
- package/src/client/actions/GuildEmojisUpdate.js +2 -2
- package/src/client/actions/GuildIntegrationsUpdate.js +19 -0
- package/src/client/actions/GuildMemberRemove.js +6 -8
- package/src/client/actions/GuildMemberUpdate.js +6 -7
- package/src/client/actions/GuildRoleCreate.js +4 -6
- package/src/client/actions/GuildRoleDelete.js +3 -4
- package/src/client/actions/GuildRoleUpdate.js +39 -0
- package/src/client/actions/GuildRolesPositionUpdate.js +3 -3
- package/src/client/actions/GuildScheduledEventCreate.js +27 -0
- package/src/client/actions/GuildScheduledEventDelete.js +3 -4
- package/src/client/actions/GuildScheduledEventUpdate.js +30 -0
- package/src/client/actions/GuildScheduledEventUserAdd.js +3 -4
- package/src/client/actions/GuildScheduledEventUserRemove.js +3 -4
- package/src/client/actions/GuildSoundboardSoundDelete.js +3 -4
- package/src/client/actions/GuildStickerCreate.js +3 -4
- package/src/client/actions/GuildStickerDelete.js +3 -4
- package/src/client/actions/GuildStickerUpdate.js +3 -4
- package/src/client/actions/GuildStickersUpdate.js +2 -2
- package/src/client/actions/GuildUpdate.js +3 -4
- package/src/client/actions/InteractionCreate.js +15 -18
- package/src/client/actions/InviteCreate.js +27 -0
- package/src/client/actions/InviteDelete.js +29 -0
- package/src/client/actions/MessageCreate.js +3 -4
- package/src/client/actions/MessageDelete.js +3 -4
- package/src/client/actions/MessageDeleteBulk.js +3 -5
- package/src/client/actions/MessagePollVoteAdd.js +3 -4
- package/src/client/actions/MessagePollVoteRemove.js +3 -4
- package/src/client/actions/MessageReactionAdd.js +5 -7
- package/src/client/actions/MessageReactionRemove.js +4 -5
- package/src/client/actions/MessageReactionRemoveAll.js +4 -5
- package/src/client/actions/MessageReactionRemoveEmoji.js +4 -5
- package/src/client/actions/MessageUpdate.js +2 -2
- package/src/client/actions/PresenceUpdate.js +45 -0
- package/src/client/actions/StageInstanceCreate.js +3 -4
- package/src/client/actions/StageInstanceDelete.js +3 -4
- package/src/client/actions/StageInstanceUpdate.js +3 -4
- package/src/client/actions/ThreadCreate.js +3 -5
- package/src/client/actions/ThreadDelete.js +26 -0
- package/src/client/actions/ThreadListSync.js +60 -0
- package/src/client/actions/ThreadMemberUpdate.js +30 -0
- package/src/client/actions/ThreadMembersUpdate.js +3 -5
- package/src/client/actions/TypingStart.js +5 -6
- package/src/client/actions/UserUpdate.js +3 -4
- package/src/client/actions/VoiceStateUpdate.js +43 -0
- package/src/client/actions/WebhooksUpdate.js +37 -0
- package/src/client/voice/ClientVoiceManager.js +6 -10
- package/src/client/websocket/WebSocketManager.js +407 -0
- package/src/client/websocket/WebSocketShard.js +234 -0
- package/src/client/websocket/handlers/APPLICATION_COMMAND_PERMISSIONS_UPDATE.js +2 -27
- package/src/client/websocket/handlers/AUTO_MODERATION_ACTION_EXECUTION.js +2 -15
- package/src/client/websocket/handlers/AUTO_MODERATION_RULE_CREATE.js +2 -16
- package/src/client/websocket/handlers/AUTO_MODERATION_RULE_DELETE.js +2 -19
- package/src/client/websocket/handlers/AUTO_MODERATION_RULE_UPDATE.js +2 -18
- package/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.js +1 -2
- package/src/client/websocket/handlers/CHANNEL_UPDATE.js +1 -2
- package/src/client/websocket/handlers/ENTITLEMENT_CREATE.js +2 -12
- package/src/client/websocket/handlers/ENTITLEMENT_DELETE.js +2 -16
- package/src/client/websocket/handlers/ENTITLEMENT_UPDATE.js +2 -14
- package/src/client/websocket/handlers/GUILD_AUDIT_LOG_ENTRY_CREATE.js +2 -17
- package/src/client/websocket/handlers/GUILD_BAN_ADD.js +2 -13
- package/src/client/websocket/handlers/GUILD_BAN_REMOVE.js +2 -18
- package/src/client/websocket/handlers/GUILD_CREATE.js +5 -7
- package/src/client/websocket/handlers/GUILD_DELETE.js +2 -34
- package/src/client/websocket/handlers/GUILD_INTEGRATIONS_UPDATE.js +2 -13
- package/src/client/websocket/handlers/GUILD_MEMBERS_CHUNK.js +1 -3
- package/src/client/websocket/handlers/GUILD_MEMBER_ADD.js +11 -9
- package/src/client/websocket/handlers/GUILD_MEMBER_REMOVE.js +2 -2
- package/src/client/websocket/handlers/GUILD_MEMBER_UPDATE.js +2 -2
- package/src/client/websocket/handlers/GUILD_ROLE_UPDATE.js +2 -19
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_CREATE.js +2 -15
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_UPDATE.js +2 -17
- package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUNDS_UPDATE.js +1 -2
- package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_CREATE.js +1 -2
- package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_UPDATE.js +1 -2
- package/src/client/websocket/handlers/INVITE_CREATE.js +2 -18
- package/src/client/websocket/handlers/INVITE_DELETE.js +2 -21
- package/src/client/websocket/handlers/MESSAGE_UPDATE.js +1 -2
- package/src/client/websocket/handlers/PRESENCE_UPDATE.js +2 -40
- package/src/client/websocket/handlers/RATE_LIMITED.js +2 -1
- package/src/client/websocket/handlers/READY.js +5 -8
- package/src/client/websocket/handlers/RESUMED.js +14 -0
- package/src/client/websocket/handlers/SOUNDBOARD_SOUNDS.js +1 -2
- package/src/client/websocket/handlers/SUBSCRIPTION_CREATE.js +1 -2
- package/src/client/websocket/handlers/SUBSCRIPTION_DELETE.js +1 -2
- package/src/client/websocket/handlers/SUBSCRIPTION_UPDATE.js +1 -2
- package/src/client/websocket/handlers/THREAD_DELETE.js +2 -15
- package/src/client/websocket/handlers/THREAD_LIST_SYNC.js +2 -49
- package/src/client/websocket/handlers/THREAD_MEMBER_UPDATE.js +2 -23
- package/src/client/websocket/handlers/THREAD_UPDATE.js +1 -2
- package/src/client/websocket/handlers/VOICE_CHANNEL_EFFECT_SEND.js +2 -3
- package/src/client/websocket/handlers/VOICE_SERVER_UPDATE.js +3 -30
- package/src/client/websocket/handlers/VOICE_STATE_UPDATE.js +2 -35
- package/src/client/websocket/handlers/WEBHOOKS_UPDATE.js +2 -14
- package/src/client/websocket/handlers/index.js +75 -74
- package/src/errors/DJSError.js +7 -7
- package/src/errors/ErrorCodes.js +134 -58
- package/src/errors/Messages.js +143 -115
- package/src/errors/index.js +3 -5
- package/src/index.js +227 -234
- package/src/managers/ApplicationCommandManager.js +24 -60
- package/src/managers/ApplicationCommandPermissionsManager.js +33 -57
- package/src/managers/ApplicationEmojiManager.js +8 -18
- package/src/managers/AutoModerationRuleManager.js +6 -24
- package/src/managers/BaseGuildEmojiManager.js +85 -0
- package/src/managers/BaseManager.js +1 -3
- package/src/managers/CachedManager.js +8 -12
- package/src/managers/CategoryChannelChildManager.js +4 -10
- package/src/managers/ChannelManager.js +8 -70
- package/src/managers/DMMessageManager.js +2 -4
- package/src/managers/DataManager.js +5 -10
- package/src/managers/EntitlementManager.js +8 -19
- package/src/managers/GuildApplicationCommandManager.js +3 -6
- package/src/managers/GuildBanManager.js +52 -27
- package/src/managers/GuildChannelManager.js +54 -91
- package/src/managers/GuildEmojiManager.js +18 -108
- package/src/managers/GuildEmojiRoleManager.js +14 -24
- package/src/managers/GuildForumThreadManager.js +5 -10
- package/src/managers/GuildInviteManager.js +27 -51
- package/src/managers/GuildManager.js +185 -45
- package/src/managers/GuildMemberManager.js +105 -89
- package/src/managers/GuildMemberRoleManager.js +14 -29
- package/src/managers/GuildMessageManager.js +2 -20
- package/src/managers/GuildScheduledEventManager.js +13 -31
- package/src/managers/GuildSoundboardSoundManager.js +5 -17
- package/src/managers/GuildStickerManager.js +21 -34
- package/src/managers/GuildTextThreadManager.js +5 -9
- package/src/managers/MessageManager.js +77 -64
- package/src/managers/PartialGroupDMMessageManager.js +2 -4
- package/src/managers/PermissionOverwriteManager.js +15 -26
- package/src/managers/PollAnswerVoterManager.js +2 -14
- package/src/managers/PresenceManager.js +6 -11
- package/src/managers/ReactionManager.js +6 -13
- package/src/managers/ReactionUserManager.js +4 -11
- package/src/managers/RoleManager.js +74 -76
- package/src/managers/StageInstanceManager.js +8 -18
- package/src/managers/SubscriptionManager.js +4 -9
- package/src/managers/ThreadManager.js +13 -33
- package/src/managers/ThreadMemberManager.js +34 -27
- package/src/managers/UserManager.js +34 -32
- package/src/managers/VoiceStateManager.js +4 -9
- package/src/sharding/Shard.js +40 -64
- package/src/sharding/ShardClientUtil.js +60 -60
- package/src/sharding/ShardingManager.js +30 -89
- package/src/structures/ActionRow.js +18 -6
- package/src/structures/ActionRowBuilder.js +35 -0
- package/src/structures/AnonymousGuild.js +10 -14
- package/src/structures/ApplicationCommand.js +49 -67
- package/src/structures/ApplicationEmoji.js +5 -22
- package/src/structures/ApplicationRoleConnectionMetadata.js +0 -6
- package/src/structures/Attachment.js +7 -25
- package/src/structures/AttachmentBuilder.js +111 -0
- package/src/structures/AutoModerationActionExecution.js +2 -17
- package/src/structures/AutoModerationRule.js +17 -46
- package/src/structures/AutocompleteInteraction.js +4 -14
- package/src/structures/Base.js +2 -4
- package/src/structures/BaseChannel.js +4 -21
- package/src/structures/BaseGuild.js +7 -19
- package/src/structures/BaseGuildEmoji.js +13 -13
- package/src/structures/BaseGuildTextChannel.js +16 -45
- package/src/structures/BaseGuildVoiceChannel.js +12 -43
- package/src/structures/BaseInteraction.js +25 -54
- package/src/structures/BaseSelectMenuComponent.js +2 -8
- package/src/structures/ButtonBuilder.js +44 -0
- package/src/structures/ButtonComponent.js +2 -9
- package/src/structures/ButtonInteraction.js +2 -3
- package/src/structures/CategoryChannel.js +3 -8
- package/src/structures/ChannelSelectMenuBuilder.js +31 -0
- package/src/structures/ChannelSelectMenuComponent.js +2 -4
- package/src/structures/ChannelSelectMenuInteraction.js +2 -5
- package/src/structures/ChatInputCommandInteraction.js +4 -7
- package/src/structures/ClientApplication.js +12 -60
- package/src/structures/ClientPresence.js +10 -15
- package/src/structures/ClientUser.js +19 -36
- package/src/structures/CommandInteraction.js +7 -27
- package/src/structures/CommandInteractionOptionResolver.js +8 -36
- package/src/structures/Component.js +1 -7
- package/src/structures/ContainerComponent.js +3 -9
- package/src/structures/ContextMenuCommandInteraction.js +5 -9
- package/src/structures/DMChannel.js +15 -34
- package/src/structures/DirectoryChannel.js +2 -6
- package/src/structures/Embed.js +2 -19
- package/src/structures/EmbedBuilder.js +50 -0
- package/src/structures/Emoji.js +19 -19
- package/src/structures/Entitlement.js +2 -22
- package/src/structures/FileComponent.js +3 -7
- package/src/structures/ForumChannel.js +3 -6
- package/src/structures/Guild.js +131 -187
- package/src/structures/GuildAuditLogs.js +6 -12
- package/src/structures/GuildAuditLogsEntry.js +63 -88
- package/src/structures/GuildBan.js +3 -9
- package/src/structures/GuildChannel.js +33 -68
- package/src/structures/GuildEmoji.js +7 -19
- package/src/structures/GuildMember.js +58 -107
- package/src/structures/GuildOnboarding.js +2 -9
- package/src/structures/GuildOnboardingPrompt.js +2 -12
- package/src/structures/GuildOnboardingPromptOption.js +2 -12
- package/src/structures/GuildPreview.js +21 -30
- package/src/structures/GuildPreviewEmoji.js +2 -5
- package/src/structures/GuildScheduledEvent.js +19 -59
- package/src/structures/GuildTemplate.js +45 -24
- package/src/structures/Integration.js +7 -30
- package/src/structures/IntegrationApplication.js +12 -9
- package/src/structures/InteractionCallback.js +1 -10
- package/src/structures/InteractionCallbackResource.js +2 -7
- package/src/structures/InteractionCallbackResponse.js +3 -6
- package/src/structures/InteractionCollector.js +36 -23
- package/src/structures/InteractionResponse.js +102 -0
- package/src/structures/InteractionWebhook.js +6 -14
- package/src/structures/Invite.js +341 -0
- package/src/structures/InviteGuild.js +4 -6
- package/src/structures/InviteStageInstance.js +87 -0
- package/src/structures/LabelComponent.js +3 -3
- package/src/structures/MediaChannel.js +2 -3
- package/src/structures/MediaGalleryComponent.js +3 -6
- package/src/structures/MediaGalleryItem.js +2 -7
- package/src/structures/MentionableSelectMenuBuilder.js +32 -0
- package/src/structures/MentionableSelectMenuComponent.js +2 -3
- package/src/structures/MentionableSelectMenuInteraction.js +3 -8
- package/src/structures/Message.js +100 -169
- package/src/structures/MessageCollector.js +5 -16
- package/src/structures/MessageComponentInteraction.js +14 -34
- package/src/structures/MessageContextMenuCommandInteraction.js +2 -4
- package/src/structures/MessageMentions.js +4 -30
- package/src/structures/MessagePayload.js +90 -92
- package/src/structures/MessageReaction.js +17 -31
- package/src/structures/ModalBuilder.js +36 -0
- package/src/structures/{ModalComponentResolver.js → ModalSubmitFields.js} +31 -37
- package/src/structures/ModalSubmitInteraction.js +55 -54
- package/src/structures/NewsChannel.js +32 -0
- package/src/structures/OAuth2Guild.js +3 -6
- package/src/structures/PartialGroupDMChannel.js +11 -23
- package/src/structures/PermissionOverwrites.js +25 -47
- package/src/structures/Poll.js +4 -19
- package/src/structures/PollAnswer.js +29 -13
- package/src/structures/Presence.js +13 -57
- package/src/structures/PrimaryEntryPointCommandInteraction.js +2 -3
- package/src/structures/ReactionCollector.js +4 -21
- package/src/structures/ReactionEmoji.js +3 -5
- package/src/structures/Role.js +48 -65
- package/src/structures/RoleSelectMenuBuilder.js +31 -0
- package/src/structures/RoleSelectMenuComponent.js +2 -3
- package/src/structures/RoleSelectMenuInteraction.js +2 -5
- package/src/structures/SKU.js +2 -9
- package/src/structures/SectionComponent.js +3 -7
- package/src/structures/SelectMenuBuilder.js +26 -0
- package/src/structures/SelectMenuComponent.js +26 -0
- package/src/structures/SelectMenuInteraction.js +26 -0
- package/src/structures/SelectMenuOptionBuilder.js +26 -0
- package/src/structures/SeparatorComponent.js +2 -5
- package/src/structures/SoundboardSound.js +2 -18
- package/src/structures/StageChannel.js +4 -13
- package/src/structures/StageInstance.js +16 -19
- package/src/structures/Sticker.js +4 -28
- package/src/structures/StickerPack.js +4 -16
- package/src/structures/StringSelectMenuBuilder.js +79 -0
- package/src/structures/StringSelectMenuComponent.js +2 -4
- package/src/structures/StringSelectMenuInteraction.js +2 -4
- package/src/structures/StringSelectMenuOptionBuilder.js +49 -0
- package/src/structures/Subscription.js +1 -15
- package/src/structures/Team.js +7 -16
- package/src/structures/TeamMember.js +15 -9
- package/src/structures/TextChannel.js +3 -6
- package/src/structures/TextDisplayComponent.js +2 -4
- package/src/structures/TextInputBuilder.js +31 -0
- package/src/structures/TextInputComponent.js +2 -5
- package/src/structures/ThreadChannel.js +35 -85
- package/src/structures/ThreadMember.js +12 -17
- package/src/structures/ThreadOnlyChannel.js +15 -36
- package/src/structures/ThumbnailComponent.js +3 -8
- package/src/structures/Typing.js +2 -10
- package/src/structures/UnfurledMediaItem.js +2 -5
- package/src/structures/User.js +68 -60
- package/src/structures/UserContextMenuCommandInteraction.js +2 -5
- package/src/structures/UserSelectMenuBuilder.js +31 -0
- package/src/structures/UserSelectMenuComponent.js +2 -3
- package/src/structures/UserSelectMenuInteraction.js +3 -7
- package/src/structures/VoiceChannel.js +4 -11
- package/src/structures/VoiceChannelEffect.js +2 -12
- package/src/structures/VoiceRegion.js +2 -7
- package/src/structures/VoiceState.js +10 -36
- package/src/structures/Webhook.js +37 -65
- package/src/structures/WelcomeChannel.js +5 -12
- package/src/structures/WelcomeScreen.js +3 -8
- package/src/structures/Widget.js +3 -13
- package/src/structures/WidgetMember.js +2 -17
- package/src/structures/interfaces/Application.js +10 -19
- package/src/structures/interfaces/Collector.js +12 -45
- package/src/structures/interfaces/InteractionResponses.js +152 -43
- package/src/structures/interfaces/TextBasedChannel.js +99 -83
- package/src/util/APITypes.js +16 -30
- package/src/util/ActivityFlagsBitField.js +2 -5
- package/src/util/ApplicationFlagsBitField.js +6 -11
- package/src/util/AttachmentFlagsBitField.js +2 -5
- package/src/util/BitField.js +8 -27
- package/src/util/ChannelFlagsBitField.js +6 -11
- package/src/util/Channels.js +61 -73
- package/src/util/Colors.js +43 -43
- package/src/util/Components.js +82 -61
- package/src/util/Constants.js +124 -94
- package/src/util/DataResolver.js +17 -36
- package/src/util/Enums.js +1 -2
- package/src/util/Events.js +14 -3
- package/src/util/Formatters.js +413 -0
- package/src/util/GuildMemberFlagsBitField.js +5 -9
- package/src/util/IntentsBitField.js +6 -10
- package/src/util/InviteFlagsBitField.js +1 -2
- package/src/util/LimitedCollection.js +6 -13
- package/src/util/LolkaSnowflake.js +14 -1
- package/src/util/MessageFlagsBitField.js +6 -11
- package/src/util/Options.js +57 -35
- package/src/util/Partials.js +4 -5
- package/src/util/PermissionsBitField.js +8 -21
- package/src/util/RoleFlagsBitField.js +2 -5
- package/src/util/SKUFlagsBitField.js +1 -4
- package/src/util/ShardEvents.js +3 -1
- package/src/util/Status.js +21 -5
- package/src/util/Sweepers.js +13 -59
- package/src/util/SystemChannelFlagsBitField.js +6 -11
- package/src/util/ThreadMemberFlagsBitField.js +2 -6
- package/src/util/Transformers.js +18 -17
- package/src/util/UserFlagsBitField.js +2 -6
- package/src/util/Util.js +97 -148
- package/src/util/WebSocketShardEvents.js +25 -0
- package/typings/index.d.mts +2392 -1768
- package/typings/index.d.ts +2392 -1768
- package/typings/rawDataTypes.d.ts +211 -0
- package/src/structures/ActivityInstance.js +0 -52
- package/src/structures/ActivityLocation.js +0 -65
- package/src/structures/AnnouncementChannel.js +0 -29
- package/src/structures/AuthorizingIntegrationOwners.js +0 -64
- package/src/structures/BaseInvite.js +0 -187
- package/src/structures/GroupDMInvite.js +0 -37
- package/src/structures/GuildInvite.js +0 -223
- package/src/util/Invites.js +0 -31
package/src/client/Client.js
CHANGED
|
@@ -1,163 +1,114 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const process = require('node:process');
|
|
4
|
-
const { clearTimeout, setImmediate, setTimeout } = require('node:timers');
|
|
5
4
|
const { Collection } = require('@discordjs/collection');
|
|
6
|
-
const {
|
|
7
|
-
const {
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const {
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const {
|
|
23
|
-
const {
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
const {
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const WaitingForGuildEvents = [GatewayDispatchEvents.GuildCreate, GatewayDispatchEvents.GuildDelete];
|
|
38
|
-
const BeforeReadyWhitelist = [
|
|
39
|
-
GatewayDispatchEvents.Ready,
|
|
40
|
-
GatewayDispatchEvents.Resumed,
|
|
41
|
-
GatewayDispatchEvents.GuildCreate,
|
|
42
|
-
GatewayDispatchEvents.GuildDelete,
|
|
43
|
-
GatewayDispatchEvents.GuildMembersChunk,
|
|
44
|
-
GatewayDispatchEvents.GuildMemberAdd,
|
|
45
|
-
GatewayDispatchEvents.GuildMemberRemove,
|
|
46
|
-
];
|
|
5
|
+
const { makeURLSearchParams } = require('@discordjs/rest');
|
|
6
|
+
const { OAuth2Scopes, Routes } = require('discord-api-types/v10');
|
|
7
|
+
const BaseClient = require('./BaseClient');
|
|
8
|
+
const ActionsManager = require('./actions/ActionsManager');
|
|
9
|
+
const ClientVoiceManager = require('./voice/ClientVoiceManager');
|
|
10
|
+
const WebSocketManager = require('./websocket/WebSocketManager');
|
|
11
|
+
const { DiscordjsError, DiscordjsTypeError, DiscordjsRangeError, ErrorCodes } = require('../errors');
|
|
12
|
+
const BaseGuildEmojiManager = require('../managers/BaseGuildEmojiManager');
|
|
13
|
+
const ChannelManager = require('../managers/ChannelManager');
|
|
14
|
+
const GuildManager = require('../managers/GuildManager');
|
|
15
|
+
const UserManager = require('../managers/UserManager');
|
|
16
|
+
const ShardClientUtil = require('../sharding/ShardClientUtil');
|
|
17
|
+
const ClientPresence = require('../structures/ClientPresence');
|
|
18
|
+
const GuildPreview = require('../structures/GuildPreview');
|
|
19
|
+
const GuildTemplate = require('../structures/GuildTemplate');
|
|
20
|
+
const Invite = require('../structures/Invite');
|
|
21
|
+
const { SoundboardSound } = require('../structures/SoundboardSound');
|
|
22
|
+
const { Sticker } = require('../structures/Sticker');
|
|
23
|
+
const StickerPack = require('../structures/StickerPack');
|
|
24
|
+
const VoiceRegion = require('../structures/VoiceRegion');
|
|
25
|
+
const Webhook = require('../structures/Webhook');
|
|
26
|
+
const Widget = require('../structures/Widget');
|
|
27
|
+
const { resolveInviteCode, resolveGuildTemplateCode } = require('../util/DataResolver');
|
|
28
|
+
const Events = require('../util/Events');
|
|
29
|
+
const IntentsBitField = require('../util/IntentsBitField');
|
|
30
|
+
const Options = require('../util/Options');
|
|
31
|
+
const PermissionsBitField = require('../util/PermissionsBitField');
|
|
32
|
+
const Status = require('../util/Status');
|
|
33
|
+
const Sweepers = require('../util/Sweepers');
|
|
34
|
+
|
|
35
|
+
let deprecationEmittedForPremiumStickerPacks = false;
|
|
47
36
|
|
|
48
37
|
/**
|
|
49
38
|
* The main hub for interacting with the Discord API, and the starting point for any bot.
|
|
50
|
-
*
|
|
51
|
-
* @extends {AsyncEventEmitter}
|
|
39
|
+
* @extends {BaseClient}
|
|
52
40
|
*/
|
|
53
|
-
class Client extends
|
|
41
|
+
class Client extends BaseClient {
|
|
54
42
|
/**
|
|
55
43
|
* @param {ClientOptions} options Options for the client
|
|
56
44
|
*/
|
|
57
45
|
constructor(options) {
|
|
58
|
-
super();
|
|
59
|
-
|
|
60
|
-
if (typeof options !== 'object' || options === null) {
|
|
61
|
-
throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'options', 'object', true);
|
|
62
|
-
}
|
|
46
|
+
super(options);
|
|
63
47
|
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
* The options the client was instantiated with
|
|
67
|
-
*
|
|
68
|
-
* @type {ClientOptions}
|
|
69
|
-
*/
|
|
70
|
-
this.options = {
|
|
71
|
-
...defaultOptions,
|
|
72
|
-
...options,
|
|
73
|
-
presence: {
|
|
74
|
-
...defaultOptions.presence,
|
|
75
|
-
...options.presence,
|
|
76
|
-
},
|
|
77
|
-
sweepers: {
|
|
78
|
-
...defaultOptions.sweepers,
|
|
79
|
-
...options.sweepers,
|
|
80
|
-
},
|
|
81
|
-
ws: {
|
|
82
|
-
...defaultOptions.ws,
|
|
83
|
-
...options.ws,
|
|
84
|
-
},
|
|
85
|
-
rest: {
|
|
86
|
-
...defaultOptions.rest,
|
|
87
|
-
...options.rest,
|
|
88
|
-
userAgentAppendix: options.rest?.userAgentAppendix
|
|
89
|
-
? `${Options.userAgentAppendix} ${options.rest.userAgentAppendix}`
|
|
90
|
-
: Options.userAgentAppendix,
|
|
91
|
-
},
|
|
92
|
-
};
|
|
48
|
+
const data = require('node:worker_threads').workerData ?? process.env;
|
|
49
|
+
const defaults = Options.createDefault();
|
|
93
50
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
this.rest = new REST(this.options.rest);
|
|
51
|
+
if (this.options.shards === defaults.shards) {
|
|
52
|
+
if ('SHARDS' in data) {
|
|
53
|
+
this.options.shards = JSON.parse(data.SHARDS);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
100
56
|
|
|
101
|
-
this.
|
|
57
|
+
if (this.options.shardCount === defaults.shardCount) {
|
|
58
|
+
if ('SHARD_COUNT' in data) {
|
|
59
|
+
this.options.shardCount = Number(data.SHARD_COUNT);
|
|
60
|
+
} else if (Array.isArray(this.options.shards)) {
|
|
61
|
+
this.options.shardCount = this.options.shards.length;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
102
64
|
|
|
103
|
-
const
|
|
65
|
+
const typeofShards = typeof this.options.shards;
|
|
104
66
|
|
|
105
|
-
if (this.options.
|
|
106
|
-
|
|
107
|
-
this.options.ws.shardIds = Array.isArray(shards) ? shards : [shards];
|
|
67
|
+
if (typeofShards === 'undefined' && typeof this.options.shardCount === 'number') {
|
|
68
|
+
this.options.shards = Array.from({ length: this.options.shardCount }, (_, i) => i);
|
|
108
69
|
}
|
|
109
70
|
|
|
110
|
-
if (this.options.
|
|
111
|
-
this.options.ws.shardCount = Number(data.SHARD_COUNT);
|
|
112
|
-
}
|
|
71
|
+
if (typeofShards === 'number') this.options.shards = [this.options.shards];
|
|
113
72
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
73
|
+
if (Array.isArray(this.options.shards)) {
|
|
74
|
+
this.options.shards = [
|
|
75
|
+
...new Set(
|
|
76
|
+
this.options.shards.filter(item => !isNaN(item) && item >= 0 && item < Infinity && item === (item | 0)),
|
|
77
|
+
),
|
|
78
|
+
];
|
|
79
|
+
}
|
|
121
80
|
|
|
122
81
|
this._validateOptions();
|
|
123
82
|
|
|
124
83
|
/**
|
|
125
|
-
* The
|
|
126
|
-
*
|
|
127
|
-
* @type {Status}
|
|
128
|
-
* @private
|
|
84
|
+
* The WebSocket manager of the client
|
|
85
|
+
* @type {WebSocketManager}
|
|
129
86
|
*/
|
|
130
|
-
this.
|
|
87
|
+
this.ws = new WebSocketManager(this);
|
|
131
88
|
|
|
132
89
|
/**
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
* @name Client#expectedGuilds
|
|
136
|
-
* @type {Set<string>}
|
|
90
|
+
* The action manager of the client
|
|
91
|
+
* @type {ActionsManager}
|
|
137
92
|
* @private
|
|
138
93
|
*/
|
|
139
|
-
|
|
94
|
+
this.actions = new ActionsManager(this);
|
|
140
95
|
|
|
141
96
|
/**
|
|
142
|
-
* The
|
|
143
|
-
*
|
|
144
|
-
* @name Client#readyTimeout
|
|
145
|
-
* @type {?NodeJS.Timeout}
|
|
146
|
-
* @private
|
|
97
|
+
* The voice manager of the client
|
|
98
|
+
* @type {ClientVoiceManager}
|
|
147
99
|
*/
|
|
148
|
-
|
|
100
|
+
this.voice = new ClientVoiceManager(this);
|
|
149
101
|
|
|
150
102
|
/**
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
* @type {ActionsManager}
|
|
154
|
-
* @private
|
|
103
|
+
* Shard helpers for the client (only if the process was spawned from a {@link ShardingManager})
|
|
104
|
+
* @type {?ShardClientUtil}
|
|
155
105
|
*/
|
|
156
|
-
this.
|
|
106
|
+
this.shard = process.env.SHARDING_MANAGER
|
|
107
|
+
? ShardClientUtil.singleton(this, process.env.SHARDING_MANAGER_MODE)
|
|
108
|
+
: null;
|
|
157
109
|
|
|
158
110
|
/**
|
|
159
111
|
* The user manager of this client
|
|
160
|
-
*
|
|
161
112
|
* @type {UserManager}
|
|
162
113
|
*/
|
|
163
114
|
this.users = new UserManager(this);
|
|
@@ -165,7 +116,6 @@ class Client extends AsyncEventEmitter {
|
|
|
165
116
|
/**
|
|
166
117
|
* A manager of all the guilds the client is currently handling -
|
|
167
118
|
* as long as sharding isn't being used, this will be *every* guild the bot is a member of
|
|
168
|
-
*
|
|
169
119
|
* @type {GuildManager}
|
|
170
120
|
*/
|
|
171
121
|
this.guilds = new GuildManager(this);
|
|
@@ -175,116 +125,71 @@ class Client extends AsyncEventEmitter {
|
|
|
175
125
|
* as long as sharding isn't being used, this will be *every* channel in *every* guild the bot
|
|
176
126
|
* is a member of. Note that DM channels will not be initially cached, and thus not be present
|
|
177
127
|
* in the Manager without their explicit fetching or use.
|
|
178
|
-
*
|
|
179
128
|
* @type {ChannelManager}
|
|
180
129
|
*/
|
|
181
130
|
this.channels = new ChannelManager(this);
|
|
182
131
|
|
|
183
132
|
/**
|
|
184
133
|
* The sweeping functions and their intervals used to periodically sweep caches
|
|
185
|
-
*
|
|
186
134
|
* @type {Sweepers}
|
|
187
135
|
*/
|
|
188
136
|
this.sweepers = new Sweepers(this, this.options.sweepers);
|
|
189
137
|
|
|
138
|
+
/**
|
|
139
|
+
* The presence of the Client
|
|
140
|
+
* @private
|
|
141
|
+
* @type {ClientPresence}
|
|
142
|
+
*/
|
|
143
|
+
this.presence = new ClientPresence(this, this.options.presence);
|
|
144
|
+
|
|
190
145
|
Object.defineProperty(this, 'token', { writable: true });
|
|
191
146
|
if (!this.token && 'DISCORD_TOKEN' in process.env) {
|
|
192
147
|
/**
|
|
193
148
|
* Authorization token for the logged in bot.
|
|
194
149
|
* If present, this defaults to `process.env.DISCORD_TOKEN` when instantiating the client
|
|
195
150
|
* <warn>This should be kept private at all times.</warn>
|
|
196
|
-
*
|
|
197
151
|
* @type {?string}
|
|
198
152
|
*/
|
|
199
153
|
this.token = process.env.DISCORD_TOKEN;
|
|
200
|
-
} else if (this.options.ws.token) {
|
|
201
|
-
this.token = this.options.ws.token;
|
|
202
154
|
} else {
|
|
203
155
|
this.token = null;
|
|
204
156
|
}
|
|
205
157
|
|
|
206
|
-
const wsOptions = {
|
|
207
|
-
...this.options.ws,
|
|
208
|
-
intents: this.options.intents.bitfield,
|
|
209
|
-
fetchGatewayInformation: () => this.rest.get(Routes.gatewayBot()),
|
|
210
|
-
// Explicitly nulled to always be set using `setToken` in `login`
|
|
211
|
-
token: null,
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* The WebSocket manager of the client
|
|
216
|
-
*
|
|
217
|
-
* @type {WebSocketManager}
|
|
218
|
-
*/
|
|
219
|
-
this.ws = new WebSocketManager(wsOptions);
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Shard helpers for the client (only if the process was spawned from a {@link ShardingManager})
|
|
223
|
-
*
|
|
224
|
-
* @type {?ShardClientUtil}
|
|
225
|
-
*/
|
|
226
|
-
this.shard = process.env.SHARDING_MANAGER
|
|
227
|
-
? ShardClientUtil.singleton(this, process.env.SHARDING_MANAGER_MODE)
|
|
228
|
-
: null;
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* The voice manager of the client
|
|
232
|
-
*
|
|
233
|
-
* @type {ClientVoiceManager}
|
|
234
|
-
*/
|
|
235
|
-
this.voice = new ClientVoiceManager(this);
|
|
236
|
-
|
|
237
158
|
/**
|
|
238
159
|
* User that the client is logged in as
|
|
239
|
-
*
|
|
240
160
|
* @type {?ClientUser}
|
|
241
161
|
*/
|
|
242
162
|
this.user = null;
|
|
243
163
|
|
|
244
164
|
/**
|
|
245
165
|
* The application of this bot
|
|
246
|
-
*
|
|
247
166
|
* @type {?ClientApplication}
|
|
248
167
|
*/
|
|
249
168
|
this.application = null;
|
|
250
169
|
|
|
251
|
-
/**
|
|
252
|
-
* The latencies of the WebSocketShard connections
|
|
253
|
-
*
|
|
254
|
-
* @type {Collection<number, number>}
|
|
255
|
-
*/
|
|
256
|
-
this.pings = new Collection();
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* The last time a ping was sent (a timestamp) for each WebSocketShard connection
|
|
260
|
-
*
|
|
261
|
-
* @type {Collection<number, number>}
|
|
262
|
-
*/
|
|
263
|
-
this.lastPingTimestamps = new Collection();
|
|
264
|
-
|
|
265
170
|
/**
|
|
266
171
|
* Timestamp of the time the client was last {@link Status.Ready} at
|
|
267
|
-
*
|
|
268
172
|
* @type {?number}
|
|
269
173
|
*/
|
|
270
174
|
this.readyTimestamp = null;
|
|
175
|
+
}
|
|
271
176
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
177
|
+
/**
|
|
178
|
+
* A manager of all the custom emojis that the client has access to
|
|
179
|
+
* @type {BaseGuildEmojiManager}
|
|
180
|
+
* @readonly
|
|
181
|
+
*/
|
|
182
|
+
get emojis() {
|
|
183
|
+
const emojis = new BaseGuildEmojiManager(this);
|
|
184
|
+
for (const guild of this.guilds.cache.values()) {
|
|
185
|
+
if (guild.available) for (const emoji of guild.emojis.cache.values()) emojis.cache.set(emoji.id, emoji);
|
|
186
|
+
}
|
|
187
|
+
return emojis;
|
|
282
188
|
}
|
|
283
189
|
|
|
284
190
|
/**
|
|
285
191
|
* Time at which the client was last regarded as being in the {@link Status.Ready} state
|
|
286
192
|
* (each time the client disconnects and successfully reconnects, this will be overwritten)
|
|
287
|
-
*
|
|
288
193
|
* @type {?Date}
|
|
289
194
|
* @readonly
|
|
290
195
|
*/
|
|
@@ -294,7 +199,6 @@ class Client extends AsyncEventEmitter {
|
|
|
294
199
|
|
|
295
200
|
/**
|
|
296
201
|
* How long it has been since the client last entered the {@link Status.Ready} state in milliseconds
|
|
297
|
-
*
|
|
298
202
|
* @type {?number}
|
|
299
203
|
* @readonly
|
|
300
204
|
*/
|
|
@@ -304,7 +208,6 @@ class Client extends AsyncEventEmitter {
|
|
|
304
208
|
|
|
305
209
|
/**
|
|
306
210
|
* Logs the client in, establishing a WebSocket connection to Discord.
|
|
307
|
-
*
|
|
308
211
|
* @param {string} [token=this.token] Token of the account to log in with
|
|
309
212
|
* @returns {Promise<string>} Token of the account used
|
|
310
213
|
* @example
|
|
@@ -312,15 +215,16 @@ class Client extends AsyncEventEmitter {
|
|
|
312
215
|
*/
|
|
313
216
|
async login(token = this.token) {
|
|
314
217
|
if (!token || typeof token !== 'string') throw new DiscordjsError(ErrorCodes.TokenInvalid);
|
|
315
|
-
this.token = token.replace(/^
|
|
218
|
+
this.token = token = token.replace(/^(Bot|Bearer)\s*/i, '');
|
|
219
|
+
this.rest.setToken(token);
|
|
220
|
+
this.emit(Events.Debug, `Provided token: ${this._censoredToken}`);
|
|
316
221
|
|
|
317
|
-
this.
|
|
222
|
+
if (this.options.presence) {
|
|
223
|
+
this.options.ws.presence = this.presence._parse(this.options.presence);
|
|
224
|
+
}
|
|
318
225
|
|
|
319
|
-
this.emit(Events.Debug, `Provided token: ${this._censoredToken}`);
|
|
320
226
|
this.emit(Events.Debug, 'Preparing to connect to the gateway...');
|
|
321
227
|
|
|
322
|
-
this.ws.setToken(this.token);
|
|
323
|
-
|
|
324
228
|
try {
|
|
325
229
|
await this.ws.connect();
|
|
326
230
|
return this.token;
|
|
@@ -330,204 +234,21 @@ class Client extends AsyncEventEmitter {
|
|
|
330
234
|
}
|
|
331
235
|
}
|
|
332
236
|
|
|
333
|
-
/**
|
|
334
|
-
* Checks if the client can be marked as ready
|
|
335
|
-
*
|
|
336
|
-
* @private
|
|
337
|
-
*/
|
|
338
|
-
async _checkReady() {
|
|
339
|
-
// Step 0. Clear the ready timeout, if it exists
|
|
340
|
-
if (this.readyTimeout) {
|
|
341
|
-
clearTimeout(this.readyTimeout);
|
|
342
|
-
this.readyTimeout = null;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
// Step 1. If we don't have any other guilds pending, we are ready
|
|
346
|
-
if (
|
|
347
|
-
!this.expectedGuilds.size &&
|
|
348
|
-
(await this.ws.fetchStatus()).every(status => status === WebSocketShardStatus.Ready)
|
|
349
|
-
) {
|
|
350
|
-
this.emit(Events.Debug, 'Client received all its guilds. Marking as fully ready.');
|
|
351
|
-
|
|
352
|
-
this._triggerClientReady();
|
|
353
|
-
return;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
const hasGuildsIntent = this.options.intents.has(GatewayIntentBits.Guilds);
|
|
357
|
-
// Step 2. Create a timeout that will mark the client as ready if there are still unavailable guilds
|
|
358
|
-
// * The timeout is 15 seconds by default
|
|
359
|
-
// * This can be optionally changed in the client options via the `waitGuildTimeout` option
|
|
360
|
-
// * a timeout time of zero will skip this timeout, which potentially could cause the Client to miss guilds.
|
|
361
|
-
|
|
362
|
-
this.readyTimeout = setTimeout(
|
|
363
|
-
() => {
|
|
364
|
-
this.emit(
|
|
365
|
-
Events.Debug,
|
|
366
|
-
`${
|
|
367
|
-
hasGuildsIntent
|
|
368
|
-
? `Client did not receive any guild packets in ${this.options.waitGuildTimeout} ms.`
|
|
369
|
-
: 'Client will not receive anymore guild packets.'
|
|
370
|
-
}\nUnavailable guild count: ${this.expectedGuilds.size}`,
|
|
371
|
-
);
|
|
372
|
-
|
|
373
|
-
this.readyTimeout = null;
|
|
374
|
-
|
|
375
|
-
this._triggerClientReady();
|
|
376
|
-
},
|
|
377
|
-
hasGuildsIntent ? this.options.waitGuildTimeout : 0,
|
|
378
|
-
).unref();
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* Attaches event handlers to the WebSocketShardManager from `@discordjs/ws`.
|
|
383
|
-
*
|
|
384
|
-
* @private
|
|
385
|
-
*/
|
|
386
|
-
_attachEvents() {
|
|
387
|
-
this.ws.on(WebSocketShardEvents.Debug, (message, shardId) =>
|
|
388
|
-
this.emit(Events.Debug, `[WS => ${typeof shardId === 'number' ? `Shard ${shardId}` : 'Manager'}] ${message}`),
|
|
389
|
-
);
|
|
390
|
-
this.ws.on(WebSocketShardEvents.Dispatch, this._handlePacket.bind(this));
|
|
391
|
-
|
|
392
|
-
this.ws.on(WebSocketShardEvents.HeartbeatComplete, ({ heartbeatAt, latency }, shardId) => {
|
|
393
|
-
this.emit(Events.Debug, `[WS => Shard ${shardId}] Heartbeat acknowledged, latency of ${latency}ms.`);
|
|
394
|
-
this.lastPingTimestamps.set(shardId, heartbeatAt);
|
|
395
|
-
this.pings.set(shardId, latency);
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
/**
|
|
400
|
-
* Processes a packet and queues it if this WebSocketManager is not ready.
|
|
401
|
-
*
|
|
402
|
-
* @param {GatewayDispatchPayload} packet The packet to be handled
|
|
403
|
-
* @param {number} shardId The shardId that received this packet
|
|
404
|
-
* @private
|
|
405
|
-
*/
|
|
406
|
-
async _handlePacket(packet, shardId) {
|
|
407
|
-
if (this.status !== Status.Ready && !BeforeReadyWhitelist.includes(packet.t)) {
|
|
408
|
-
this.incomingPacketQueue.push({ packet, shardId });
|
|
409
|
-
} else {
|
|
410
|
-
if (this.incomingPacketQueue.length) {
|
|
411
|
-
const item = this.incomingPacketQueue.shift();
|
|
412
|
-
setImmediate(async () => {
|
|
413
|
-
await this._handlePacket(item.packet, item.shardId);
|
|
414
|
-
}).unref();
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
if (PacketHandlers[packet.t]) {
|
|
418
|
-
PacketHandlers[packet.t](this, packet, shardId);
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
if (packet.t === GatewayDispatchEvents.Ready) {
|
|
422
|
-
await this._checkReady();
|
|
423
|
-
} else if (this.status === Status.WaitingForGuilds && WaitingForGuildEvents.includes(packet.t)) {
|
|
424
|
-
this.expectedGuilds.delete(packet.d.id);
|
|
425
|
-
await this._checkReady();
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
/**
|
|
431
|
-
* Broadcasts a packet to every shard of this client handles.
|
|
432
|
-
*
|
|
433
|
-
* @param {Object} packet The packet to send
|
|
434
|
-
* @private
|
|
435
|
-
*/
|
|
436
|
-
async _broadcast(packet) {
|
|
437
|
-
const shardIds = await this.ws.getShardIds();
|
|
438
|
-
return Promise.all(shardIds.map(shardId => this.ws.send(shardId, packet)));
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
/**
|
|
442
|
-
* Causes the client to be marked as ready and emits the ready event.
|
|
443
|
-
*
|
|
444
|
-
* @private
|
|
445
|
-
*/
|
|
446
|
-
_triggerClientReady() {
|
|
447
|
-
this.status = Status.Ready;
|
|
448
|
-
|
|
449
|
-
this.readyTimestamp = Date.now();
|
|
450
|
-
|
|
451
|
-
/**
|
|
452
|
-
* Emitted when the client becomes ready to start working.
|
|
453
|
-
*
|
|
454
|
-
* @event Client#clientReady
|
|
455
|
-
* @param {Client} client The client
|
|
456
|
-
*/
|
|
457
|
-
this.emit(Events.ClientReady, this);
|
|
458
|
-
}
|
|
459
|
-
|
|
460
237
|
/**
|
|
461
238
|
* Returns whether the client has logged in, indicative of being able to access
|
|
462
239
|
* properties such as `user` and `application`.
|
|
463
|
-
*
|
|
464
240
|
* @returns {boolean}
|
|
465
241
|
*/
|
|
466
242
|
isReady() {
|
|
467
|
-
return this.status === Status.Ready;
|
|
243
|
+
return !this.ws.destroyed && this.ws.status === Status.Ready;
|
|
468
244
|
}
|
|
469
245
|
|
|
470
246
|
/**
|
|
471
|
-
*
|
|
472
|
-
*
|
|
473
|
-
* @type {?number}
|
|
474
|
-
* @readonly
|
|
475
|
-
*/
|
|
476
|
-
get ping() {
|
|
477
|
-
return this.pings.size ? this.pings.reduce((a, b) => a + b, 0) / this.pings.size : null;
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
/**
|
|
481
|
-
* Options used for deleting a webhook.
|
|
482
|
-
*
|
|
483
|
-
* @typedef {Object} WebhookDeleteOptions
|
|
484
|
-
* @property {string} [token] Token of the webhook
|
|
485
|
-
* @property {string} [reason] The reason for deleting the webhook
|
|
486
|
-
*/
|
|
487
|
-
|
|
488
|
-
/**
|
|
489
|
-
* Deletes a webhook.
|
|
490
|
-
*
|
|
491
|
-
* @param {Snowflake} id The webhook's id
|
|
492
|
-
* @param {WebhookDeleteOptions} [options] Options for deleting the webhook
|
|
493
|
-
* @returns {Promise<void>}
|
|
494
|
-
*/
|
|
495
|
-
async deleteWebhook(id, { token, reason } = {}) {
|
|
496
|
-
await this.rest.delete(Routes.webhook(id, token), { auth: !token, reason });
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
/**
|
|
500
|
-
* Increments max listeners by one, if they are not zero.
|
|
501
|
-
*
|
|
502
|
-
* @private
|
|
503
|
-
*/
|
|
504
|
-
incrementMaxListeners() {
|
|
505
|
-
const maxListeners = this.getMaxListeners();
|
|
506
|
-
if (maxListeners !== 0) {
|
|
507
|
-
this.setMaxListeners(maxListeners + 1);
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
/**
|
|
512
|
-
* Decrements max listeners by one, if they are not zero.
|
|
513
|
-
*
|
|
514
|
-
* @private
|
|
515
|
-
*/
|
|
516
|
-
decrementMaxListeners() {
|
|
517
|
-
const maxListeners = this.getMaxListeners();
|
|
518
|
-
if (maxListeners !== 0) {
|
|
519
|
-
this.setMaxListeners(maxListeners - 1);
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
|
|
523
|
-
/**
|
|
524
|
-
* Destroys all assets used by the client.
|
|
525
|
-
*
|
|
247
|
+
* Logs out, terminates the connection to Discord, and destroys the client.
|
|
526
248
|
* @returns {Promise<void>}
|
|
527
249
|
*/
|
|
528
250
|
async destroy() {
|
|
529
|
-
|
|
530
|
-
this.rest.clearHandlerSweeper();
|
|
251
|
+
super.destroy();
|
|
531
252
|
|
|
532
253
|
this.sweepers.destroy();
|
|
533
254
|
await this.ws.destroy();
|
|
@@ -537,16 +258,13 @@ class Client extends AsyncEventEmitter {
|
|
|
537
258
|
|
|
538
259
|
/**
|
|
539
260
|
* Options used when fetching an invite from Discord.
|
|
540
|
-
*
|
|
541
261
|
* @typedef {Object} ClientFetchInviteOptions
|
|
542
|
-
* @property {boolean} [withCounts] Whether to include approximate member counts
|
|
543
262
|
* @property {Snowflake} [guildScheduledEventId] The id of the guild scheduled event to include with
|
|
544
263
|
* the invite
|
|
545
264
|
*/
|
|
546
265
|
|
|
547
266
|
/**
|
|
548
267
|
* Obtains an invite from Discord.
|
|
549
|
-
*
|
|
550
268
|
* @param {InviteResolvable} invite Invite code or URL
|
|
551
269
|
* @param {ClientFetchInviteOptions} [options] Options for fetching the invite
|
|
552
270
|
* @returns {Promise<Invite>}
|
|
@@ -555,21 +273,18 @@ class Client extends AsyncEventEmitter {
|
|
|
555
273
|
* .then(invite => console.log(`Obtained invite with code: ${invite.code}`))
|
|
556
274
|
* .catch(console.error);
|
|
557
275
|
*/
|
|
558
|
-
async fetchInvite(invite,
|
|
276
|
+
async fetchInvite(invite, options) {
|
|
559
277
|
const code = resolveInviteCode(invite);
|
|
560
|
-
|
|
561
278
|
const query = makeURLSearchParams({
|
|
562
|
-
with_counts:
|
|
563
|
-
guild_scheduled_event_id: guildScheduledEventId,
|
|
279
|
+
with_counts: true,
|
|
280
|
+
guild_scheduled_event_id: options?.guildScheduledEventId,
|
|
564
281
|
});
|
|
565
|
-
|
|
566
282
|
const data = await this.rest.get(Routes.invite(code), { query });
|
|
567
|
-
return
|
|
283
|
+
return new Invite(this, data);
|
|
568
284
|
}
|
|
569
285
|
|
|
570
286
|
/**
|
|
571
287
|
* Obtains a template from Discord.
|
|
572
|
-
*
|
|
573
288
|
* @param {GuildTemplateResolvable} template Template code or URL
|
|
574
289
|
* @returns {Promise<GuildTemplate>}
|
|
575
290
|
* @example
|
|
@@ -585,7 +300,6 @@ class Client extends AsyncEventEmitter {
|
|
|
585
300
|
|
|
586
301
|
/**
|
|
587
302
|
* Obtains a webhook from Discord.
|
|
588
|
-
*
|
|
589
303
|
* @param {Snowflake} id The webhook's id
|
|
590
304
|
* @param {string} [token] Token for the webhook
|
|
591
305
|
* @returns {Promise<Webhook>}
|
|
@@ -601,7 +315,6 @@ class Client extends AsyncEventEmitter {
|
|
|
601
315
|
|
|
602
316
|
/**
|
|
603
317
|
* Obtains the available voice regions from Discord.
|
|
604
|
-
*
|
|
605
318
|
* @returns {Promise<Collection<string, VoiceRegion>>}
|
|
606
319
|
* @example
|
|
607
320
|
* client.fetchVoiceRegions()
|
|
@@ -617,7 +330,6 @@ class Client extends AsyncEventEmitter {
|
|
|
617
330
|
|
|
618
331
|
/**
|
|
619
332
|
* Obtains a sticker from Discord.
|
|
620
|
-
*
|
|
621
333
|
* @param {Snowflake} id The sticker's id
|
|
622
334
|
* @returns {Promise<Sticker>}
|
|
623
335
|
* @example
|
|
@@ -632,14 +344,12 @@ class Client extends AsyncEventEmitter {
|
|
|
632
344
|
|
|
633
345
|
/**
|
|
634
346
|
* Options for fetching sticker packs.
|
|
635
|
-
*
|
|
636
347
|
* @typedef {Object} StickerPackFetchOptions
|
|
637
348
|
* @property {Snowflake} [packId] The id of the sticker pack to fetch
|
|
638
349
|
*/
|
|
639
350
|
|
|
640
351
|
/**
|
|
641
352
|
* Obtains the list of available sticker packs.
|
|
642
|
-
*
|
|
643
353
|
* @param {StickerPackFetchOptions} [options={}] Options for fetching sticker packs
|
|
644
354
|
* @returns {Promise<Collection<Snowflake, StickerPack>|StickerPack>}
|
|
645
355
|
* A collection of sticker packs, or a single sticker pack if a packId was provided
|
|
@@ -654,17 +364,34 @@ class Client extends AsyncEventEmitter {
|
|
|
654
364
|
*/
|
|
655
365
|
async fetchStickerPacks({ packId } = {}) {
|
|
656
366
|
if (packId) {
|
|
657
|
-
const
|
|
658
|
-
return new StickerPack(this,
|
|
367
|
+
const data = await this.rest.get(Routes.stickerPack(packId));
|
|
368
|
+
return new StickerPack(this, data);
|
|
659
369
|
}
|
|
660
370
|
|
|
661
371
|
const data = await this.rest.get(Routes.stickerPacks());
|
|
662
372
|
return new Collection(data.sticker_packs.map(stickerPack => [stickerPack.id, new StickerPack(this, stickerPack)]));
|
|
663
373
|
}
|
|
664
374
|
|
|
375
|
+
/**
|
|
376
|
+
* Obtains the list of available sticker packs.
|
|
377
|
+
* @returns {Promise<Collection<Snowflake, StickerPack>>}
|
|
378
|
+
* @deprecated Use {@link Client#fetchStickerPacks} instead.
|
|
379
|
+
*/
|
|
380
|
+
fetchPremiumStickerPacks() {
|
|
381
|
+
if (!deprecationEmittedForPremiumStickerPacks) {
|
|
382
|
+
process.emitWarning(
|
|
383
|
+
'The Client#fetchPremiumStickerPacks() method is deprecated. Use Client#fetchStickerPacks() instead.',
|
|
384
|
+
'DeprecationWarning',
|
|
385
|
+
);
|
|
386
|
+
|
|
387
|
+
deprecationEmittedForPremiumStickerPacks = true;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
return this.fetchStickerPacks();
|
|
391
|
+
}
|
|
392
|
+
|
|
665
393
|
/**
|
|
666
394
|
* Obtains the list of default soundboard sounds.
|
|
667
|
-
*
|
|
668
395
|
* @returns {Promise<Collection<string, SoundboardSound>>}
|
|
669
396
|
* @example
|
|
670
397
|
* client.fetchDefaultSoundboardSounds()
|
|
@@ -678,7 +405,6 @@ class Client extends AsyncEventEmitter {
|
|
|
678
405
|
|
|
679
406
|
/**
|
|
680
407
|
* Obtains a guild preview from Discord, available for all guilds the bot is in and all Discoverable guilds.
|
|
681
|
-
*
|
|
682
408
|
* @param {GuildResolvable} guild The guild to fetch the preview for
|
|
683
409
|
* @returns {Promise<GuildPreview>}
|
|
684
410
|
*/
|
|
@@ -691,7 +417,6 @@ class Client extends AsyncEventEmitter {
|
|
|
691
417
|
|
|
692
418
|
/**
|
|
693
419
|
* Obtains the widget data of a guild from Discord, available for guilds with the widget enabled.
|
|
694
|
-
*
|
|
695
420
|
* @param {GuildResolvable} guild The guild to fetch the widget data for
|
|
696
421
|
* @returns {Promise<Widget>}
|
|
697
422
|
*/
|
|
@@ -704,7 +429,6 @@ class Client extends AsyncEventEmitter {
|
|
|
704
429
|
|
|
705
430
|
/**
|
|
706
431
|
* Options for {@link Client#generateInvite}.
|
|
707
|
-
*
|
|
708
432
|
* @typedef {Object} InviteGenerationOptions
|
|
709
433
|
* @property {OAuth2Scopes[]} scopes Scopes that should be requested
|
|
710
434
|
* @property {PermissionResolvable} [permissions] Permissions to request
|
|
@@ -714,7 +438,6 @@ class Client extends AsyncEventEmitter {
|
|
|
714
438
|
|
|
715
439
|
/**
|
|
716
440
|
* Generates a link that can be used to invite the bot to a guild.
|
|
717
|
-
*
|
|
718
441
|
* @param {InviteGenerationOptions} [options={}] Options for the invite
|
|
719
442
|
* @returns {string}
|
|
720
443
|
* @example
|
|
@@ -741,19 +464,15 @@ class Client extends AsyncEventEmitter {
|
|
|
741
464
|
if (scopes === undefined) {
|
|
742
465
|
throw new DiscordjsTypeError(ErrorCodes.InvalidMissingScopes);
|
|
743
466
|
}
|
|
744
|
-
|
|
745
467
|
if (!Array.isArray(scopes)) {
|
|
746
468
|
throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'scopes', 'Array of Invite Scopes', true);
|
|
747
469
|
}
|
|
748
|
-
|
|
749
470
|
if (!scopes.some(scope => [OAuth2Scopes.Bot, OAuth2Scopes.ApplicationsCommands].includes(scope))) {
|
|
750
471
|
throw new DiscordjsTypeError(ErrorCodes.InvalidMissingScopes);
|
|
751
472
|
}
|
|
752
|
-
|
|
753
473
|
if (!scopes.includes(OAuth2Scopes.Bot) && options.permissions) {
|
|
754
474
|
throw new DiscordjsTypeError(ErrorCodes.InvalidScopesWithPermissions);
|
|
755
475
|
}
|
|
756
|
-
|
|
757
476
|
const validScopes = Object.values(OAuth2Scopes);
|
|
758
477
|
const invalidScope = scopes.find(scope => !validScopes.includes(scope));
|
|
759
478
|
if (invalidScope) {
|
|
@@ -781,12 +500,14 @@ class Client extends AsyncEventEmitter {
|
|
|
781
500
|
}
|
|
782
501
|
|
|
783
502
|
toJSON() {
|
|
784
|
-
return
|
|
503
|
+
return super.toJSON({
|
|
504
|
+
actions: false,
|
|
505
|
+
presence: false,
|
|
506
|
+
});
|
|
785
507
|
}
|
|
786
508
|
|
|
787
509
|
/**
|
|
788
510
|
* Partially censored client token for debug logging purposes.
|
|
789
|
-
*
|
|
790
511
|
* @type {?string}
|
|
791
512
|
* @readonly
|
|
792
513
|
* @private
|
|
@@ -796,91 +517,79 @@ class Client extends AsyncEventEmitter {
|
|
|
796
517
|
|
|
797
518
|
return this.token
|
|
798
519
|
.split('.')
|
|
799
|
-
.map((val,
|
|
520
|
+
.map((val, i) => (i > 1 ? val.replace(/./g, '*') : val))
|
|
800
521
|
.join('.');
|
|
801
522
|
}
|
|
802
523
|
|
|
803
524
|
/**
|
|
804
525
|
* Calls {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/eval} on a script
|
|
805
526
|
* with the client as `this`.
|
|
806
|
-
*
|
|
807
527
|
* @param {string} script Script to eval
|
|
808
528
|
* @returns {*}
|
|
809
529
|
* @private
|
|
810
530
|
*/
|
|
811
531
|
_eval(script) {
|
|
812
|
-
// eslint-disable-next-line no-eval
|
|
813
532
|
return eval(script);
|
|
814
533
|
}
|
|
815
534
|
|
|
816
535
|
/**
|
|
817
536
|
* Validates the client options.
|
|
818
|
-
*
|
|
819
537
|
* @param {ClientOptions} [options=this.options] Options to validate
|
|
820
538
|
* @private
|
|
821
539
|
*/
|
|
822
540
|
_validateOptions(options = this.options) {
|
|
823
|
-
if (options.intents === undefined
|
|
541
|
+
if (options.intents === undefined) {
|
|
824
542
|
throw new DiscordjsTypeError(ErrorCodes.ClientMissingIntents);
|
|
825
543
|
} else {
|
|
826
|
-
options.intents = new IntentsBitField(options.intents
|
|
544
|
+
options.intents = new IntentsBitField(options.intents).freeze();
|
|
545
|
+
}
|
|
546
|
+
if (typeof options.shardCount !== 'number' || isNaN(options.shardCount) || options.shardCount < 1) {
|
|
547
|
+
throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'shardCount', 'a number greater than or equal to 1');
|
|
548
|
+
}
|
|
549
|
+
if (options.shards && !(options.shards === 'auto' || Array.isArray(options.shards))) {
|
|
550
|
+
throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'shards', "'auto', a number or array of numbers");
|
|
551
|
+
}
|
|
552
|
+
if (options.shards && !options.shards.length) throw new DiscordjsRangeError(ErrorCodes.ClientInvalidProvidedShards);
|
|
553
|
+
if (typeof options.makeCache !== 'function') {
|
|
554
|
+
throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'makeCache', 'a function');
|
|
827
555
|
}
|
|
828
|
-
|
|
829
556
|
if (typeof options.sweepers !== 'object' || options.sweepers === null) {
|
|
830
557
|
throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'sweepers', 'an object');
|
|
831
558
|
}
|
|
832
|
-
|
|
833
559
|
if (!Array.isArray(options.partials)) {
|
|
834
560
|
throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'partials', 'an Array');
|
|
835
561
|
}
|
|
836
|
-
|
|
837
|
-
if (typeof options.waitGuildTimeout !== 'number' || Number.isNaN(options.waitGuildTimeout)) {
|
|
562
|
+
if (typeof options.waitGuildTimeout !== 'number' || isNaN(options.waitGuildTimeout)) {
|
|
838
563
|
throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'waitGuildTimeout', 'a number');
|
|
839
564
|
}
|
|
840
|
-
|
|
841
565
|
if (typeof options.failIfNotExists !== 'boolean') {
|
|
842
566
|
throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'failIfNotExists', 'a boolean');
|
|
843
567
|
}
|
|
844
|
-
|
|
845
568
|
if (typeof options.enforceNonce !== 'boolean') {
|
|
846
569
|
throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'enforceNonce', 'a boolean');
|
|
847
570
|
}
|
|
848
|
-
|
|
849
571
|
if (
|
|
850
572
|
(typeof options.allowedMentions !== 'object' && options.allowedMentions !== undefined) ||
|
|
851
573
|
options.allowedMentions === null
|
|
852
574
|
) {
|
|
853
575
|
throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'allowedMentions', 'an object');
|
|
854
576
|
}
|
|
855
|
-
|
|
577
|
+
if (typeof options.presence !== 'object' || options.presence === null) {
|
|
578
|
+
throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'presence', 'an object');
|
|
579
|
+
}
|
|
856
580
|
if (typeof options.ws !== 'object' || options.ws === null) {
|
|
857
581
|
throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'ws', 'an object');
|
|
858
582
|
}
|
|
859
|
-
|
|
860
|
-
if (
|
|
861
|
-
(typeof options.presence !== 'object' || options.presence === null) &&
|
|
862
|
-
options.ws.initialPresence === undefined
|
|
863
|
-
) {
|
|
864
|
-
throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'presence', 'an object');
|
|
865
|
-
} else {
|
|
866
|
-
options.ws.initialPresence = options.ws.initialPresence ?? this.presence._parse(this.options.presence);
|
|
867
|
-
}
|
|
868
|
-
|
|
869
583
|
if (typeof options.rest !== 'object' || options.rest === null) {
|
|
870
584
|
throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'rest', 'an object');
|
|
871
585
|
}
|
|
872
|
-
|
|
873
586
|
if (typeof options.jsonTransformer !== 'function') {
|
|
874
587
|
throw new DiscordjsTypeError(ErrorCodes.ClientInvalidOption, 'jsonTransformer', 'a function');
|
|
875
588
|
}
|
|
876
589
|
}
|
|
877
|
-
|
|
878
|
-
async [Symbol.asyncDispose]() {
|
|
879
|
-
await this.destroy();
|
|
880
|
-
}
|
|
881
590
|
}
|
|
882
591
|
|
|
883
|
-
exports
|
|
592
|
+
module.exports = Client;
|
|
884
593
|
|
|
885
594
|
/**
|
|
886
595
|
* @class SnowflakeUtil
|
|
@@ -899,20 +608,17 @@ exports.Client = Client;
|
|
|
899
608
|
* 000000111011000111100001101001000101000000 00001 00000 000000000000
|
|
900
609
|
* number of milliseconds since Discord epoch worker pid increment
|
|
901
610
|
* ```
|
|
902
|
-
*
|
|
903
611
|
* @typedef {string} Snowflake
|
|
904
612
|
*/
|
|
905
613
|
|
|
906
614
|
/**
|
|
907
615
|
* Emitted for general debugging information.
|
|
908
|
-
*
|
|
909
616
|
* @event Client#debug
|
|
910
617
|
* @param {string} info The debug information
|
|
911
618
|
*/
|
|
912
619
|
|
|
913
620
|
/**
|
|
914
621
|
* Emitted for general warnings.
|
|
915
|
-
*
|
|
916
622
|
* @event Client#warn
|
|
917
623
|
* @param {string} info The warning
|
|
918
624
|
*/
|
|
@@ -922,11 +628,6 @@ exports.Client = Client;
|
|
|
922
628
|
* @see {@link https://discord.js.org/docs/packages/collection/stable/Collection:Class}
|
|
923
629
|
*/
|
|
924
630
|
|
|
925
|
-
/**
|
|
926
|
-
* @external REST
|
|
927
|
-
* @see {@link https://discord.js.org/docs/packages/rest/stable/REST:Class}
|
|
928
|
-
*/
|
|
929
|
-
|
|
930
631
|
/**
|
|
931
632
|
* @external ImageURLOptions
|
|
932
633
|
* @see {@link https://discord.js.org/docs/packages/rest/stable/ImageURLOptions:Interface}
|