discord-selfbot-v13.js 0.0.1-security → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of discord-selfbot-v13.js might be problematic. Click here for more details.
- package/LICENSE +674 -0
- package/README.md +119 -5
- package/package.json +101 -6
- package/src/WebSocket.js +39 -0
- package/src/client/BaseClient.js +87 -0
- package/src/client/Client.js +1154 -0
- package/src/client/WebhookClient.js +61 -0
- package/src/client/actions/Action.js +115 -0
- package/src/client/actions/ActionsManager.js +72 -0
- 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 +23 -0
- package/src/client/actions/ChannelDelete.js +39 -0
- package/src/client/actions/ChannelUpdate.js +34 -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 +21 -0
- package/src/client/actions/GuildDelete.js +65 -0
- package/src/client/actions/GuildEmojiCreate.js +20 -0
- package/src/client/actions/GuildEmojiDelete.js +21 -0
- package/src/client/actions/GuildEmojiUpdate.js +20 -0
- package/src/client/actions/GuildEmojisUpdate.js +34 -0
- package/src/client/actions/GuildIntegrationsUpdate.js +19 -0
- package/src/client/actions/GuildMemberRemove.js +33 -0
- package/src/client/actions/GuildMemberUpdate.js +44 -0
- package/src/client/actions/GuildRoleCreate.js +25 -0
- package/src/client/actions/GuildRoleDelete.js +31 -0
- package/src/client/actions/GuildRoleUpdate.js +39 -0
- package/src/client/actions/GuildRolesPositionUpdate.js +21 -0
- package/src/client/actions/GuildScheduledEventCreate.js +27 -0
- package/src/client/actions/GuildScheduledEventDelete.js +31 -0
- package/src/client/actions/GuildScheduledEventUpdate.js +30 -0
- package/src/client/actions/GuildScheduledEventUserAdd.js +32 -0
- package/src/client/actions/GuildScheduledEventUserRemove.js +32 -0
- package/src/client/actions/GuildStickerCreate.js +20 -0
- package/src/client/actions/GuildStickerDelete.js +21 -0
- package/src/client/actions/GuildStickerUpdate.js +20 -0
- package/src/client/actions/GuildStickersUpdate.js +34 -0
- package/src/client/actions/GuildUpdate.js +33 -0
- package/src/client/actions/InteractionCreate.js +115 -0
- package/src/client/actions/InviteCreate.js +28 -0
- package/src/client/actions/InviteDelete.js +30 -0
- package/src/client/actions/MessageCreate.js +50 -0
- package/src/client/actions/MessageDelete.js +32 -0
- package/src/client/actions/MessageDeleteBulk.js +46 -0
- package/src/client/actions/MessageReactionAdd.js +56 -0
- package/src/client/actions/MessageReactionRemove.js +45 -0
- package/src/client/actions/MessageReactionRemoveAll.js +33 -0
- package/src/client/actions/MessageReactionRemoveEmoji.js +28 -0
- package/src/client/actions/MessageUpdate.js +26 -0
- package/src/client/actions/PresenceUpdate.js +45 -0
- package/src/client/actions/StageInstanceCreate.js +28 -0
- package/src/client/actions/StageInstanceDelete.js +33 -0
- package/src/client/actions/StageInstanceUpdate.js +30 -0
- package/src/client/actions/ThreadCreate.js +24 -0
- package/src/client/actions/ThreadDelete.js +32 -0
- package/src/client/actions/ThreadListSync.js +59 -0
- package/src/client/actions/ThreadMemberUpdate.js +30 -0
- package/src/client/actions/ThreadMembersUpdate.js +34 -0
- package/src/client/actions/TypingStart.js +29 -0
- package/src/client/actions/UserUpdate.js +35 -0
- package/src/client/actions/VoiceStateUpdate.js +57 -0
- package/src/client/actions/WebhooksUpdate.js +20 -0
- package/src/client/voice/ClientVoiceManager.js +51 -0
- package/src/client/websocket/WebSocketManager.js +412 -0
- package/src/client/websocket/WebSocketShard.js +908 -0
- package/src/client/websocket/handlers/APPLICATION_COMMAND_AUTOCOMPLETE_RESPONSE.js +23 -0
- package/src/client/websocket/handlers/APPLICATION_COMMAND_CREATE.js +18 -0
- package/src/client/websocket/handlers/APPLICATION_COMMAND_DELETE.js +20 -0
- package/src/client/websocket/handlers/APPLICATION_COMMAND_PERMISSIONS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/APPLICATION_COMMAND_UPDATE.js +20 -0
- package/src/client/websocket/handlers/AUTO_MODERATION_ACTION_EXECUTION.js +5 -0
- package/src/client/websocket/handlers/AUTO_MODERATION_RULE_CREATE.js +5 -0
- package/src/client/websocket/handlers/AUTO_MODERATION_RULE_DELETE.js +5 -0
- package/src/client/websocket/handlers/AUTO_MODERATION_RULE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/CALL_CREATE.js +14 -0
- package/src/client/websocket/handlers/CALL_DELETE.js +11 -0
- package/src/client/websocket/handlers/CALL_UPDATE.js +11 -0
- package/src/client/websocket/handlers/CHANNEL_CREATE.js +5 -0
- package/src/client/websocket/handlers/CHANNEL_DELETE.js +5 -0
- package/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.js +22 -0
- package/src/client/websocket/handlers/CHANNEL_RECIPIENT_ADD.js +16 -0
- package/src/client/websocket/handlers/CHANNEL_RECIPIENT_REMOVE.js +16 -0
- package/src/client/websocket/handlers/CHANNEL_UPDATE.js +16 -0
- package/src/client/websocket/handlers/GUILD_APPLICATION_COMMANDS_UPDATE.js +11 -0
- package/src/client/websocket/handlers/GUILD_AUDIT_LOG_ENTRY_CREATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_BAN_ADD.js +5 -0
- package/src/client/websocket/handlers/GUILD_BAN_REMOVE.js +5 -0
- package/src/client/websocket/handlers/GUILD_CREATE.js +46 -0
- package/src/client/websocket/handlers/GUILD_DELETE.js +5 -0
- package/src/client/websocket/handlers/GUILD_EMOJIS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_INTEGRATIONS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_MEMBERS_CHUNK.js +39 -0
- package/src/client/websocket/handlers/GUILD_MEMBER_ADD.js +20 -0
- package/src/client/websocket/handlers/GUILD_MEMBER_LIST_UPDATE.js +55 -0
- package/src/client/websocket/handlers/GUILD_MEMBER_REMOVE.js +5 -0
- package/src/client/websocket/handlers/GUILD_MEMBER_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_ROLE_CREATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_ROLE_DELETE.js +5 -0
- package/src/client/websocket/handlers/GUILD_ROLE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_CREATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_DELETE.js +5 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_ADD.js +5 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_REMOVE.js +5 -0
- package/src/client/websocket/handlers/GUILD_STICKERS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_UPDATE.js +5 -0
- package/src/client/websocket/handlers/INTERACTION_CREATE.js +16 -0
- package/src/client/websocket/handlers/INTERACTION_FAILURE.js +18 -0
- package/src/client/websocket/handlers/INTERACTION_MODAL_CREATE.js +11 -0
- package/src/client/websocket/handlers/INTERACTION_SUCCESS.js +30 -0
- package/src/client/websocket/handlers/INVITE_CREATE.js +5 -0
- package/src/client/websocket/handlers/INVITE_DELETE.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_ACK.js +16 -0
- package/src/client/websocket/handlers/MESSAGE_CREATE.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_DELETE.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_DELETE_BULK.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_REACTION_ADD.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_ALL.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_REACTION_REMOVE_EMOJI.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_UPDATE.js +16 -0
- package/src/client/websocket/handlers/PRESENCE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/READY.js +172 -0
- package/src/client/websocket/handlers/RELATIONSHIP_ADD.js +17 -0
- package/src/client/websocket/handlers/RELATIONSHIP_REMOVE.js +15 -0
- package/src/client/websocket/handlers/RELATIONSHIP_UPDATE.js +18 -0
- package/src/client/websocket/handlers/RESUMED.js +14 -0
- package/src/client/websocket/handlers/STAGE_INSTANCE_CREATE.js +5 -0
- package/src/client/websocket/handlers/STAGE_INSTANCE_DELETE.js +5 -0
- package/src/client/websocket/handlers/STAGE_INSTANCE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/THREAD_CREATE.js +5 -0
- package/src/client/websocket/handlers/THREAD_DELETE.js +5 -0
- package/src/client/websocket/handlers/THREAD_LIST_SYNC.js +5 -0
- package/src/client/websocket/handlers/THREAD_MEMBERS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/THREAD_MEMBER_UPDATE.js +5 -0
- package/src/client/websocket/handlers/THREAD_UPDATE.js +16 -0
- package/src/client/websocket/handlers/TYPING_START.js +5 -0
- package/src/client/websocket/handlers/USER_GUILD_SETTINGS_UPDATE.js +12 -0
- package/src/client/websocket/handlers/USER_NOTE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/USER_SETTINGS_UPDATE.js +9 -0
- package/src/client/websocket/handlers/USER_UPDATE.js +5 -0
- package/src/client/websocket/handlers/VOICE_SERVER_UPDATE.js +6 -0
- package/src/client/websocket/handlers/VOICE_STATE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/WEBHOOKS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/index.js +86 -0
- package/src/errors/DJSError.js +61 -0
- package/src/errors/Messages.js +227 -0
- package/src/errors/index.js +4 -0
- package/src/index.js +190 -0
- package/src/main.js +42 -0
- package/src/managers/ApplicationCommandManager.js +267 -0
- package/src/managers/ApplicationCommandPermissionsManager.js +425 -0
- package/src/managers/AutoModerationRuleManager.js +296 -0
- package/src/managers/BaseGuildEmojiManager.js +80 -0
- package/src/managers/BaseManager.js +19 -0
- package/src/managers/BillingManager.js +66 -0
- package/src/managers/CachedManager.js +71 -0
- package/src/managers/ChannelManager.js +139 -0
- package/src/managers/ClientUserSettingManager.js +490 -0
- package/src/managers/DataManager.js +61 -0
- package/src/managers/DeveloperPortalManager.js +104 -0
- package/src/managers/GuildApplicationCommandManager.js +28 -0
- package/src/managers/GuildBanManager.js +204 -0
- package/src/managers/GuildChannelManager.js +502 -0
- package/src/managers/GuildEmojiManager.js +171 -0
- package/src/managers/GuildEmojiRoleManager.js +118 -0
- package/src/managers/GuildFolderManager.js +24 -0
- package/src/managers/GuildForumThreadManager.js +114 -0
- package/src/managers/GuildInviteManager.js +213 -0
- package/src/managers/GuildManager.js +304 -0
- package/src/managers/GuildMemberManager.js +724 -0
- package/src/managers/GuildMemberRoleManager.js +191 -0
- package/src/managers/GuildScheduledEventManager.js +296 -0
- package/src/managers/GuildSettingManager.js +148 -0
- package/src/managers/GuildStickerManager.js +179 -0
- package/src/managers/GuildTextThreadManager.js +98 -0
- package/src/managers/InteractionManager.js +39 -0
- package/src/managers/MessageManager.js +393 -0
- package/src/managers/PermissionOverwriteManager.js +166 -0
- package/src/managers/PresenceManager.js +58 -0
- package/src/managers/ReactionManager.js +67 -0
- package/src/managers/ReactionUserManager.js +71 -0
- package/src/managers/RelationshipManager.js +258 -0
- package/src/managers/RoleManager.js +352 -0
- package/src/managers/SessionManager.js +57 -0
- package/src/managers/StageInstanceManager.js +162 -0
- package/src/managers/ThreadManager.js +207 -0
- package/src/managers/ThreadMemberManager.js +186 -0
- package/src/managers/UserManager.js +150 -0
- package/src/managers/VoiceStateManager.js +37 -0
- package/src/rest/APIRequest.js +136 -0
- package/src/rest/APIRouter.js +53 -0
- package/src/rest/CaptchaSolver.js +78 -0
- package/src/rest/DiscordAPIError.js +103 -0
- package/src/rest/HTTPError.js +62 -0
- package/src/rest/RESTManager.js +81 -0
- package/src/rest/RateLimitError.js +55 -0
- package/src/rest/RequestHandler.js +446 -0
- package/src/sharding/Shard.js +443 -0
- package/src/sharding/ShardClientUtil.js +275 -0
- package/src/sharding/ShardingManager.js +318 -0
- package/src/structures/AnonymousGuild.js +98 -0
- package/src/structures/ApplicationCommand.js +1028 -0
- package/src/structures/ApplicationRoleConnectionMetadata.js +45 -0
- package/src/structures/AutoModerationActionExecution.js +89 -0
- package/src/structures/AutoModerationRule.js +294 -0
- package/src/structures/AutocompleteInteraction.js +106 -0
- package/src/structures/Base.js +43 -0
- package/src/structures/BaseCommandInteraction.js +211 -0
- package/src/structures/BaseGuild.js +116 -0
- package/src/structures/BaseGuildEmoji.js +56 -0
- package/src/structures/BaseGuildTextChannel.js +193 -0
- package/src/structures/BaseGuildVoiceChannel.js +243 -0
- package/src/structures/BaseMessageComponent.js +114 -0
- package/src/structures/ButtonInteraction.js +11 -0
- package/src/structures/Call.js +58 -0
- package/src/structures/CategoryChannel.js +83 -0
- package/src/structures/Channel.js +271 -0
- package/src/structures/ClientApplication.js +204 -0
- package/src/structures/ClientPresence.js +84 -0
- package/src/structures/ClientUser.js +624 -0
- package/src/structures/CommandInteraction.js +41 -0
- package/src/structures/CommandInteractionOptionResolver.js +276 -0
- package/src/structures/ContextMenuInteraction.js +65 -0
- package/src/structures/DMChannel.js +280 -0
- package/src/structures/DeveloperPortalApplication.js +520 -0
- package/src/structures/DirectoryChannel.js +20 -0
- package/src/structures/Emoji.js +148 -0
- package/src/structures/ForumChannel.js +271 -0
- package/src/structures/Guild.js +1744 -0
- package/src/structures/GuildAuditLogs.js +734 -0
- package/src/structures/GuildBan.js +59 -0
- package/src/structures/GuildBoost.js +108 -0
- package/src/structures/GuildChannel.js +454 -0
- package/src/structures/GuildEmoji.js +161 -0
- package/src/structures/GuildFolder.js +75 -0
- package/src/structures/GuildMember.js +686 -0
- package/src/structures/GuildPreview.js +191 -0
- package/src/structures/GuildPreviewEmoji.js +27 -0
- package/src/structures/GuildScheduledEvent.js +441 -0
- package/src/structures/GuildTemplate.js +236 -0
- package/src/structures/Integration.js +188 -0
- package/src/structures/IntegrationApplication.js +96 -0
- package/src/structures/Interaction.js +351 -0
- package/src/structures/InteractionCollector.js +248 -0
- package/src/structures/InteractionResponse.js +114 -0
- package/src/structures/InteractionWebhook.js +43 -0
- package/src/structures/Invite.js +375 -0
- package/src/structures/InviteGuild.js +23 -0
- package/src/structures/InviteStageInstance.js +86 -0
- package/src/structures/Message.js +1188 -0
- package/src/structures/MessageActionRow.js +103 -0
- package/src/structures/MessageAttachment.js +193 -0
- package/src/structures/MessageButton.js +231 -0
- package/src/structures/MessageCollector.js +146 -0
- package/src/structures/MessageComponentInteraction.js +120 -0
- package/src/structures/MessageContextMenuInteraction.js +20 -0
- package/src/structures/MessageEmbed.js +586 -0
- package/src/structures/MessageMentions.js +272 -0
- package/src/structures/MessagePayload.js +358 -0
- package/src/structures/MessageReaction.js +171 -0
- package/src/structures/MessageSelectMenu.js +391 -0
- package/src/structures/Modal.js +279 -0
- package/src/structures/ModalSubmitFieldsResolver.js +53 -0
- package/src/structures/ModalSubmitInteraction.js +119 -0
- package/src/structures/NewsChannel.js +32 -0
- package/src/structures/OAuth2Guild.js +28 -0
- package/src/structures/PartialGroupDMChannel.js +430 -0
- package/src/structures/PermissionOverwrites.js +196 -0
- package/src/structures/Presence.js +441 -0
- package/src/structures/ReactionCollector.js +229 -0
- package/src/structures/ReactionEmoji.js +31 -0
- package/src/structures/RichPresence.js +722 -0
- package/src/structures/Role.js +515 -0
- package/src/structures/SelectMenuInteraction.js +170 -0
- package/src/structures/Session.js +81 -0
- package/src/structures/StageChannel.js +104 -0
- package/src/structures/StageInstance.js +208 -0
- package/src/structures/Sticker.js +310 -0
- package/src/structures/StickerPack.js +95 -0
- package/src/structures/StoreChannel.js +56 -0
- package/src/structures/Team.js +167 -0
- package/src/structures/TeamMember.js +71 -0
- package/src/structures/TextChannel.js +33 -0
- package/src/structures/TextInputComponent.js +201 -0
- package/src/structures/ThreadChannel.js +626 -0
- package/src/structures/ThreadMember.js +105 -0
- package/src/structures/Typing.js +74 -0
- package/src/structures/User.js +697 -0
- package/src/structures/UserContextMenuInteraction.js +29 -0
- package/src/structures/VoiceChannel.js +110 -0
- package/src/structures/VoiceRegion.js +53 -0
- package/src/structures/VoiceState.js +306 -0
- package/src/structures/WebEmbed.js +401 -0
- package/src/structures/Webhook.js +461 -0
- package/src/structures/WelcomeChannel.js +60 -0
- package/src/structures/WelcomeScreen.js +48 -0
- package/src/structures/Widget.js +87 -0
- package/src/structures/WidgetMember.js +99 -0
- package/src/structures/interfaces/Application.js +190 -0
- package/src/structures/interfaces/Collector.js +300 -0
- package/src/structures/interfaces/InteractionResponses.js +313 -0
- package/src/structures/interfaces/TextBasedChannel.js +566 -0
- package/src/util/ActivityFlags.js +44 -0
- package/src/util/ApplicationFlags.js +74 -0
- package/src/util/BitField.js +170 -0
- package/src/util/ChannelFlags.js +45 -0
- package/src/util/Constants.js +1917 -0
- package/src/util/DataResolver.js +145 -0
- package/src/util/Formatters.js +214 -0
- package/src/util/GuildMemberFlags.js +43 -0
- package/src/util/Intents.js +74 -0
- package/src/util/LimitedCollection.js +131 -0
- package/src/util/MessageFlags.js +54 -0
- package/src/util/Options.js +360 -0
- package/src/util/Permissions.js +187 -0
- package/src/util/PremiumUsageFlags.js +31 -0
- package/src/util/PurchasedFlags.js +31 -0
- package/src/util/RemoteAuth.js +522 -0
- package/src/util/SnowflakeUtil.js +92 -0
- package/src/util/Sweepers.js +466 -0
- package/src/util/SystemChannelFlags.js +55 -0
- package/src/util/ThreadMemberFlags.js +30 -0
- package/src/util/UserFlags.js +104 -0
- package/src/util/Util.js +741 -0
- package/src/util/Voice.js +1456 -0
- package/src/util/arRPC/index.js +229 -0
- package/src/util/arRPC/process/detectable.json +1 -0
- package/src/util/arRPC/process/index.js +102 -0
- package/src/util/arRPC/process/native/index.js +5 -0
- package/src/util/arRPC/process/native/linux.js +37 -0
- package/src/util/arRPC/process/native/win32.js +25 -0
- package/src/util/arRPC/transports/ipc.js +281 -0
- package/src/util/arRPC/transports/websocket.js +128 -0
- package/typings/enums.d.ts +346 -0
- package/typings/index.d.ts +7725 -0
- package/typings/index.test-d.ts +0 -0
- package/typings/rawDataTypes.d.ts +283 -0
@@ -0,0 +1,1154 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const process = require('node:process');
|
4
|
+
const { setInterval, setTimeout } = require('node:timers');
|
5
|
+
const { Collection } = require('@discordjs/collection');
|
6
|
+
const { getVoiceConnection } = require('@discordjs/voice');
|
7
|
+
const axios = require('axios');
|
8
|
+
const chalk = require('chalk');
|
9
|
+
const BaseClient = require('./BaseClient');
|
10
|
+
const ActionsManager = require('./actions/ActionsManager');
|
11
|
+
const ClientVoiceManager = require('./voice/ClientVoiceManager');
|
12
|
+
const WebSocketManager = require('./websocket/WebSocketManager');
|
13
|
+
const { Error, TypeError, RangeError } = require('../errors');
|
14
|
+
const Discord = require('../index');
|
15
|
+
const BaseGuildEmojiManager = require('../managers/BaseGuildEmojiManager');
|
16
|
+
const BillingManager = require('../managers/BillingManager');
|
17
|
+
const ChannelManager = require('../managers/ChannelManager');
|
18
|
+
const ClientUserSettingManager = require('../managers/ClientUserSettingManager');
|
19
|
+
const DeveloperPortalManager = require('../managers/DeveloperPortalManager');
|
20
|
+
const GuildManager = require('../managers/GuildManager');
|
21
|
+
const RelationshipManager = require('../managers/RelationshipManager');
|
22
|
+
const SessionManager = require('../managers/SessionManager');
|
23
|
+
const UserManager = require('../managers/UserManager');
|
24
|
+
const VoiceStateManager = require('../managers/VoiceStateManager');
|
25
|
+
const ShardClientUtil = require('../sharding/ShardClientUtil');
|
26
|
+
const ClientPresence = require('../structures/ClientPresence');
|
27
|
+
const GuildPreview = require('../structures/GuildPreview');
|
28
|
+
const GuildTemplate = require('../structures/GuildTemplate');
|
29
|
+
const Invite = require('../structures/Invite');
|
30
|
+
const { CustomStatus } = require('../structures/RichPresence');
|
31
|
+
const { Sticker } = require('../structures/Sticker');
|
32
|
+
const StickerPack = require('../structures/StickerPack');
|
33
|
+
const VoiceRegion = require('../structures/VoiceRegion');
|
34
|
+
const Webhook = require('../structures/Webhook');
|
35
|
+
const Widget = require('../structures/Widget');
|
36
|
+
const { Events, InviteScopes, Status, captchaServices } = require('../util/Constants');
|
37
|
+
const DataResolver = require('../util/DataResolver');
|
38
|
+
const Intents = require('../util/Intents');
|
39
|
+
const Options = require('../util/Options');
|
40
|
+
const Permissions = require('../util/Permissions');
|
41
|
+
const DiscordAuthWebsocket = require('../util/RemoteAuth');
|
42
|
+
const Sweepers = require('../util/Sweepers');
|
43
|
+
const { lazy, testImportModule } = require('../util/Util');
|
44
|
+
const Message = lazy(() => require('../structures/Message').Message);
|
45
|
+
|
46
|
+
/**
|
47
|
+
* The main hub for interacting with the Discord API, and the starting point for any bot.
|
48
|
+
* @extends {BaseClient}
|
49
|
+
*/
|
50
|
+
class Client extends BaseClient {
|
51
|
+
/**
|
52
|
+
* @param {ClientOptions} options Options for the client
|
53
|
+
*/
|
54
|
+
constructor(options = {}) {
|
55
|
+
super(options);
|
56
|
+
|
57
|
+
const data = require('node:worker_threads').workerData ?? process.env;
|
58
|
+
const defaults = Options.createDefault();
|
59
|
+
|
60
|
+
if (this.options.shards === defaults.shards) {
|
61
|
+
if ('SHARDS' in data) {
|
62
|
+
this.options.shards = JSON.parse(data.SHARDS);
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
if (this.options.shardCount === defaults.shardCount) {
|
67
|
+
if ('SHARD_COUNT' in data) {
|
68
|
+
this.options.shardCount = Number(data.SHARD_COUNT);
|
69
|
+
} else if (Array.isArray(this.options.shards)) {
|
70
|
+
this.options.shardCount = this.options.shards.length;
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
const typeofShards = typeof this.options.shards;
|
75
|
+
|
76
|
+
if (typeofShards === 'undefined' && typeof this.options.shardCount === 'number') {
|
77
|
+
this.options.shards = Array.from({ length: this.options.shardCount }, (_, i) => i);
|
78
|
+
}
|
79
|
+
|
80
|
+
if (typeofShards === 'number') this.options.shards = [this.options.shards];
|
81
|
+
|
82
|
+
if (Array.isArray(this.options.shards)) {
|
83
|
+
this.options.shards = [
|
84
|
+
...new Set(
|
85
|
+
this.options.shards.filter(item => !isNaN(item) && item >= 0 && item < Infinity && item === (item | 0)),
|
86
|
+
),
|
87
|
+
];
|
88
|
+
}
|
89
|
+
|
90
|
+
this._validateOptions();
|
91
|
+
|
92
|
+
/**
|
93
|
+
* Functions called when a cache is garbage collected or the Client is destroyed
|
94
|
+
* @type {Set<Function>}
|
95
|
+
* @private
|
96
|
+
*/
|
97
|
+
this._cleanups = new Set();
|
98
|
+
|
99
|
+
/**
|
100
|
+
* The finalizers used to cleanup items.
|
101
|
+
* @type {FinalizationRegistry}
|
102
|
+
* @private
|
103
|
+
*/
|
104
|
+
this._finalizers = new FinalizationRegistry(this._finalize.bind(this));
|
105
|
+
|
106
|
+
/**
|
107
|
+
* The WebSocket manager of the client
|
108
|
+
* @type {WebSocketManager}
|
109
|
+
*/
|
110
|
+
this.ws = new WebSocketManager(this);
|
111
|
+
|
112
|
+
/**
|
113
|
+
* The action manager of the client
|
114
|
+
* @type {ActionsManager}
|
115
|
+
* @private
|
116
|
+
*/
|
117
|
+
this.actions = new ActionsManager(this);
|
118
|
+
|
119
|
+
/**
|
120
|
+
* The voice manager of the client
|
121
|
+
* @type {ClientVoiceManager}
|
122
|
+
*/
|
123
|
+
this.voice = new ClientVoiceManager(this);
|
124
|
+
|
125
|
+
/**
|
126
|
+
* A manager of the voice states of this client (Support DM / Group DM)
|
127
|
+
* @type {VoiceStateManager}
|
128
|
+
*/
|
129
|
+
this.voiceStates = new VoiceStateManager({ client: this });
|
130
|
+
|
131
|
+
/**
|
132
|
+
* Shard helpers for the client (only if the process was spawned from a {@link ShardingManager})
|
133
|
+
* @type {?ShardClientUtil}
|
134
|
+
*/
|
135
|
+
this.shard = process.env.SHARDING_MANAGER
|
136
|
+
? ShardClientUtil.singleton(this, process.env.SHARDING_MANAGER_MODE)
|
137
|
+
: null;
|
138
|
+
|
139
|
+
/**
|
140
|
+
* All of the {@link User} objects that have been cached at any point, mapped by their ids
|
141
|
+
* @type {UserManager}
|
142
|
+
*/
|
143
|
+
this.users = new UserManager(this);
|
144
|
+
|
145
|
+
// Patch
|
146
|
+
/**
|
147
|
+
* All of the relationships {@link User}
|
148
|
+
* @type {RelationshipManager}
|
149
|
+
*/
|
150
|
+
this.relationships = new RelationshipManager(this);
|
151
|
+
/**
|
152
|
+
* All of the settings {@link Object}
|
153
|
+
* @type {ClientUserSettingManager}
|
154
|
+
*/
|
155
|
+
this.settings = new ClientUserSettingManager(this);
|
156
|
+
/**
|
157
|
+
* All of the guilds the client is currently handling, mapped by their ids -
|
158
|
+
* as long as sharding isn't being used, this will be *every* guild the bot is a member of
|
159
|
+
* @type {GuildManager}
|
160
|
+
*/
|
161
|
+
this.guilds = new GuildManager(this);
|
162
|
+
|
163
|
+
/**
|
164
|
+
* Manages the API methods
|
165
|
+
* @type {BillingManager}
|
166
|
+
*/
|
167
|
+
this.billing = new BillingManager(this);
|
168
|
+
|
169
|
+
/**
|
170
|
+
* All of the sessions of the client
|
171
|
+
* @type {SessionManager}
|
172
|
+
*/
|
173
|
+
this.sessions = new SessionManager(this);
|
174
|
+
|
175
|
+
/**
|
176
|
+
* All of the {@link Channel}s that the client is currently handling, mapped by their ids -
|
177
|
+
* as long as sharding isn't being used, this will be *every* channel in *every* guild the bot
|
178
|
+
* is a member of. Note that DM channels will not be initially cached, and thus not be present
|
179
|
+
* in the Manager without their explicit fetching or use.
|
180
|
+
* @type {ChannelManager}
|
181
|
+
*/
|
182
|
+
this.channels = new ChannelManager(this);
|
183
|
+
|
184
|
+
/**
|
185
|
+
* The sweeping functions and their intervals used to periodically sweep caches
|
186
|
+
* @type {Sweepers}
|
187
|
+
*/
|
188
|
+
this.sweepers = new Sweepers(this, this.options.sweepers);
|
189
|
+
|
190
|
+
/**
|
191
|
+
* The developer portal manager of the client
|
192
|
+
* @type {DeveloperPortalManager}
|
193
|
+
*/
|
194
|
+
this.developerPortal = new DeveloperPortalManager(this);
|
195
|
+
|
196
|
+
/**
|
197
|
+
* The presence of the Client
|
198
|
+
* @private
|
199
|
+
* @type {ClientPresence}
|
200
|
+
*/
|
201
|
+
this.presence = new ClientPresence(this, this.options.presence);
|
202
|
+
|
203
|
+
Object.defineProperty(this, 'token', { writable: true });
|
204
|
+
if (!this.token && 'DISCORD_TOKEN' in process.env) {
|
205
|
+
/**
|
206
|
+
* Authorization token for the logged in bot.
|
207
|
+
* If present, this defaults to `process.env.DISCORD_TOKEN` when instantiating the client
|
208
|
+
* <warn>This should be kept private at all times.</warn>
|
209
|
+
* @type {?string}
|
210
|
+
*/
|
211
|
+
this.token = process.env.DISCORD_TOKEN;
|
212
|
+
} else {
|
213
|
+
this.token = null;
|
214
|
+
}
|
215
|
+
|
216
|
+
this._interactionCache = new Collection();
|
217
|
+
|
218
|
+
/**
|
219
|
+
* User that the client is logged in as
|
220
|
+
* @type {?ClientUser}
|
221
|
+
*/
|
222
|
+
this.user = null;
|
223
|
+
|
224
|
+
/**
|
225
|
+
* The application of this bot
|
226
|
+
* @type {?ClientApplication}
|
227
|
+
*/
|
228
|
+
this.application = null;
|
229
|
+
|
230
|
+
/**
|
231
|
+
* Time at which the client was last regarded as being in the `READY` state
|
232
|
+
* (each time the client disconnects and successfully reconnects, this will be overwritten)
|
233
|
+
* @type {?Date}
|
234
|
+
*/
|
235
|
+
this.readyAt = null;
|
236
|
+
|
237
|
+
/**
|
238
|
+
* Password cache
|
239
|
+
* @type {?string}
|
240
|
+
*/
|
241
|
+
this.password = this.options.password;
|
242
|
+
|
243
|
+
/**
|
244
|
+
* Nitro cache
|
245
|
+
* @type {Array}
|
246
|
+
*/
|
247
|
+
this.usedCodes = [];
|
248
|
+
|
249
|
+
setInterval(() => {
|
250
|
+
this.usedCodes = [];
|
251
|
+
}, 1000 * 60 * 60).unref();
|
252
|
+
|
253
|
+
this.session_id = null;
|
254
|
+
|
255
|
+
if (this.options.messageSweepInterval > 0) {
|
256
|
+
process.emitWarning(
|
257
|
+
'The message sweeping client options are deprecated, use the global sweepers instead.',
|
258
|
+
'DeprecationWarning',
|
259
|
+
);
|
260
|
+
this.sweepMessageInterval = setInterval(
|
261
|
+
this.sweepMessages.bind(this),
|
262
|
+
this.options.messageSweepInterval * 1_000,
|
263
|
+
).unref();
|
264
|
+
}
|
265
|
+
}
|
266
|
+
|
267
|
+
/**
|
268
|
+
* Session ID
|
269
|
+
* @type {?string}
|
270
|
+
* @readonly
|
271
|
+
*/
|
272
|
+
get sessionId() {
|
273
|
+
return this.session_id;
|
274
|
+
}
|
275
|
+
|
276
|
+
/**
|
277
|
+
* All custom emojis that the client has access to, mapped by their ids
|
278
|
+
* @type {BaseGuildEmojiManager}
|
279
|
+
* @readonly
|
280
|
+
*/
|
281
|
+
get emojis() {
|
282
|
+
const emojis = new BaseGuildEmojiManager(this);
|
283
|
+
for (const guild of this.guilds.cache.values()) {
|
284
|
+
if (guild.available) for (const emoji of guild.emojis.cache.values()) emojis.cache.set(emoji.id, emoji);
|
285
|
+
}
|
286
|
+
return emojis;
|
287
|
+
}
|
288
|
+
|
289
|
+
/**
|
290
|
+
* Timestamp of the time the client was last `READY` at
|
291
|
+
* @type {?number}
|
292
|
+
* @readonly
|
293
|
+
*/
|
294
|
+
get readyTimestamp() {
|
295
|
+
return this.readyAt?.getTime() ?? null;
|
296
|
+
}
|
297
|
+
|
298
|
+
/**
|
299
|
+
* How long it has been since the client last entered the `READY` state in milliseconds
|
300
|
+
* @type {?number}
|
301
|
+
* @readonly
|
302
|
+
*/
|
303
|
+
get uptime() {
|
304
|
+
return this.readyAt ? Date.now() - this.readyAt : null;
|
305
|
+
}
|
306
|
+
|
307
|
+
/**
|
308
|
+
* @external VoiceConnection
|
309
|
+
* @see {@link https://discord.js.org/#/docs/voice/main/class/VoiceConnection}
|
310
|
+
*/
|
311
|
+
/**
|
312
|
+
* Get connection to current call
|
313
|
+
* @type {?VoiceConnection}
|
314
|
+
* @readonly
|
315
|
+
*/
|
316
|
+
get callVoice() {
|
317
|
+
return getVoiceConnection(null);
|
318
|
+
}
|
319
|
+
|
320
|
+
/**
|
321
|
+
* Logs the client in, establishing a WebSocket connection to Discord.
|
322
|
+
* @param {string} [token=this.token] Token of the account to log in with
|
323
|
+
* @returns {Promise<string>} Token of the account used
|
324
|
+
* @example
|
325
|
+
* client.login('my token');
|
326
|
+
*/
|
327
|
+
async login(token = this.token) {
|
328
|
+
if (!token || typeof token !== 'string') throw new Error('TOKEN_INVALID');
|
329
|
+
this.token = token = token.replace(/^(Bot|Bearer)\s*/i, '');
|
330
|
+
this.emit(
|
331
|
+
Events.DEBUG,
|
332
|
+
`
|
333
|
+
Logging on with a user token is unfortunately against the Discord
|
334
|
+
\`Terms of Service\` <https://support.discord.com/hc/en-us/articles/115002192352>
|
335
|
+
and doing so might potentially get your account banned.
|
336
|
+
Use this at your own risk.
|
337
|
+
`,
|
338
|
+
);
|
339
|
+
this.emit(
|
340
|
+
Events.DEBUG,
|
341
|
+
`Provided token: ${token
|
342
|
+
.split('.')
|
343
|
+
.map((val, i) => (i > 1 ? val.replace(/./g, '*') : val))
|
344
|
+
.join('.')}`,
|
345
|
+
);
|
346
|
+
|
347
|
+
if (this.options.presence) {
|
348
|
+
this.options.ws.presence = this.presence._parse(this.options.presence);
|
349
|
+
}
|
350
|
+
|
351
|
+
this.emit(Events.DEBUG, 'Preparing to connect to the gateway...');
|
352
|
+
|
353
|
+
try {
|
354
|
+
await this.ws.connect();
|
355
|
+
return this.token;
|
356
|
+
} catch (error) {
|
357
|
+
this.destroy();
|
358
|
+
throw error;
|
359
|
+
}
|
360
|
+
}
|
361
|
+
|
362
|
+
/**
|
363
|
+
* Login Discord with Username and Password
|
364
|
+
* @param {string} username Email or Phone Number
|
365
|
+
* @param {?string} password Password
|
366
|
+
* @param {?string} mfaCode 2FA Code / Backup Code
|
367
|
+
* @returns {Promise<string>}
|
368
|
+
*/
|
369
|
+
async normalLogin(username, password = this.password, mfaCode) {
|
370
|
+
if (!username || !password || typeof username !== 'string' || typeof password !== 'string') {
|
371
|
+
throw new Error('NORMAL_LOGIN');
|
372
|
+
}
|
373
|
+
this.emit(
|
374
|
+
Events.DEBUG,
|
375
|
+
`Connecting to Discord with:
|
376
|
+
username: ${username}
|
377
|
+
password: ${password.replace(/./g, '*')}`,
|
378
|
+
);
|
379
|
+
const data = await this.api.auth.login.post({
|
380
|
+
data: {
|
381
|
+
login: username,
|
382
|
+
password: password,
|
383
|
+
undelete: false,
|
384
|
+
captcha_key: null,
|
385
|
+
login_source: null,
|
386
|
+
gift_code_sku_id: null,
|
387
|
+
},
|
388
|
+
auth: false,
|
389
|
+
});
|
390
|
+
this.password = password;
|
391
|
+
if (!data.token && data.ticket && data.mfa) {
|
392
|
+
this.emit(Events.DEBUG, `Using 2FA Code: ${mfaCode}`);
|
393
|
+
const normal2fa = /(\d{6})/g;
|
394
|
+
const backupCode = /([a-z0-9]{4})-([a-z0-9]{4})/g;
|
395
|
+
if (!mfaCode || typeof mfaCode !== 'string') {
|
396
|
+
throw new Error('LOGIN_FAILED_2FA');
|
397
|
+
}
|
398
|
+
if (normal2fa.test(mfaCode) || backupCode.test(mfaCode)) {
|
399
|
+
const data2 = await this.api.auth.mfa.totp.post({
|
400
|
+
data: {
|
401
|
+
code: mfaCode,
|
402
|
+
ticket: data.ticket,
|
403
|
+
login_source: null,
|
404
|
+
gift_code_sku_id: null,
|
405
|
+
},
|
406
|
+
auth: false,
|
407
|
+
});
|
408
|
+
return this.login(data2.token);
|
409
|
+
} else {
|
410
|
+
throw new Error('LOGIN_FAILED_2FA');
|
411
|
+
}
|
412
|
+
} else if (data.token) {
|
413
|
+
return this.login(data.token);
|
414
|
+
} else {
|
415
|
+
throw new Error('LOGIN_FAILED_UNKNOWN');
|
416
|
+
}
|
417
|
+
}
|
418
|
+
|
419
|
+
/**
|
420
|
+
* Switch the user
|
421
|
+
* @param {string} token User Token
|
422
|
+
* @returns {Promise<string>}
|
423
|
+
*/
|
424
|
+
switchUser(token) {
|
425
|
+
this._clearCache(this.emojis.cache);
|
426
|
+
this._clearCache(this.guilds.cache);
|
427
|
+
this._clearCache(this.channels.cache);
|
428
|
+
this._clearCache(this.users.cache);
|
429
|
+
this._clearCache(this.relationships.cache);
|
430
|
+
this._clearCache(this.sessions.cache);
|
431
|
+
this._clearCache(this.voiceStates.cache);
|
432
|
+
this.ws.status = Status.IDLE;
|
433
|
+
return this.login(token);
|
434
|
+
}
|
435
|
+
|
436
|
+
/**
|
437
|
+
* Sign in with the QR code on your phone.
|
438
|
+
* @param {DiscordAuthWebsocketOptions} options Options
|
439
|
+
* @returns {DiscordAuthWebsocket}
|
440
|
+
* @example
|
441
|
+
* client.QRLogin();
|
442
|
+
*/
|
443
|
+
QRLogin(options = {}) {
|
444
|
+
const QR = new DiscordAuthWebsocket({ ...options, autoLogin: true });
|
445
|
+
this.emit(Events.DEBUG, `Preparing to connect to the gateway (QR Login)`, QR);
|
446
|
+
return QR.connect(this);
|
447
|
+
}
|
448
|
+
|
449
|
+
/**
|
450
|
+
* @typedef {Object} remoteAuthConfrim
|
451
|
+
* @property {function} yes Yes
|
452
|
+
* @property {function} no No
|
453
|
+
*/
|
454
|
+
|
455
|
+
/**
|
456
|
+
* Implement `remoteAuth`, like using your phone to scan a QR code
|
457
|
+
* @param {string} url URL from QR code
|
458
|
+
* @param {boolean} forceAccept Whether to force confirm `yes`
|
459
|
+
* @returns {Promise<remoteAuthConfrim | void>}
|
460
|
+
*/
|
461
|
+
async remoteAuth(url, forceAccept = false) {
|
462
|
+
if (!this.isReady()) throw new Error('CLIENT_NOT_READY', 'Remote Auth');
|
463
|
+
// Step 1: Parse URL
|
464
|
+
url = new URL(url);
|
465
|
+
if (
|
466
|
+
!['discordapp.com', 'discord.com'].includes(url.hostname) ||
|
467
|
+
!url.pathname.startsWith('/ra/') ||
|
468
|
+
url.pathname.length <= 4
|
469
|
+
) {
|
470
|
+
throw new Error('INVALID_REMOTE_AUTH_URL');
|
471
|
+
}
|
472
|
+
const hash = url.pathname.replace('/ra/', '');
|
473
|
+
// Step 2: Post > Get handshake_token
|
474
|
+
const res = await this.api.users['@me']['remote-auth'].post({
|
475
|
+
data: {
|
476
|
+
fingerprint: hash,
|
477
|
+
},
|
478
|
+
});
|
479
|
+
const handshake_token = res.handshake_token;
|
480
|
+
// Step 3: Post
|
481
|
+
const yes = () =>
|
482
|
+
this.api.users['@me']['remote-auth'].finish.post({ data: { handshake_token, temporary_token: false } });
|
483
|
+
const no = () => this.api.users['@me']['remote-auth'].cancel.post({ data: { handshake_token } });
|
484
|
+
if (forceAccept) {
|
485
|
+
return yes();
|
486
|
+
} else {
|
487
|
+
return {
|
488
|
+
yes,
|
489
|
+
no,
|
490
|
+
};
|
491
|
+
}
|
492
|
+
}
|
493
|
+
|
494
|
+
/**
|
495
|
+
* Create a new token based on the current token
|
496
|
+
* @returns {Promise<string>} New Discord Token
|
497
|
+
*/
|
498
|
+
createToken() {
|
499
|
+
return new Promise(resolve => {
|
500
|
+
// Step 1: Create DiscordAuthWebsocket
|
501
|
+
const QR = new DiscordAuthWebsocket({
|
502
|
+
hiddenLog: true,
|
503
|
+
generateQR: false,
|
504
|
+
autoLogin: false,
|
505
|
+
debug: false,
|
506
|
+
failIfError: false,
|
507
|
+
userAgent: this.options.http.headers['User-Agent'],
|
508
|
+
wsProperties: this.options.ws.properties,
|
509
|
+
});
|
510
|
+
// Step 2: Add event
|
511
|
+
QR.once('ready', async (_, url) => {
|
512
|
+
await this.remoteAuth(url, true);
|
513
|
+
}).once('finish', (user, token) => {
|
514
|
+
resolve(token);
|
515
|
+
});
|
516
|
+
// Step 3: Connect
|
517
|
+
QR.connect();
|
518
|
+
});
|
519
|
+
}
|
520
|
+
|
521
|
+
/**
|
522
|
+
* Emitted whenever clientOptions.checkUpdate = false
|
523
|
+
* @event Client#update
|
524
|
+
* @param {string} oldVersion Current version
|
525
|
+
* @param {string} newVersion Latest version
|
526
|
+
*/
|
527
|
+
|
528
|
+
/**
|
529
|
+
* Check for updates
|
530
|
+
* @returns {Promise<Client>}
|
531
|
+
*/
|
532
|
+
async checkUpdate() {
|
533
|
+
const res_ = await axios
|
534
|
+
.get(`https://registry.npmjs.com/${encodeURIComponent('discord.js-selfbot-v13')}`)
|
535
|
+
.catch(() => {});
|
536
|
+
try {
|
537
|
+
const latest_tag = res_.data['dist-tags'].latest;
|
538
|
+
this.emit('update', Discord.version, latest_tag);
|
539
|
+
this.emit('debug', `${chalk.greenBright('[OK]')} Check Update success`);
|
540
|
+
} catch {
|
541
|
+
this.emit('debug', `${chalk.redBright('[Fail]')} Check Update error`);
|
542
|
+
this.emit('update', Discord.version, false);
|
543
|
+
}
|
544
|
+
return this;
|
545
|
+
}
|
546
|
+
|
547
|
+
/**
|
548
|
+
* Returns whether the client has logged in, indicative of being able to access
|
549
|
+
* properties such as `user` and `application`.
|
550
|
+
* @returns {boolean}
|
551
|
+
*/
|
552
|
+
isReady() {
|
553
|
+
return this.ws.status === Status.READY;
|
554
|
+
}
|
555
|
+
|
556
|
+
/**
|
557
|
+
* Logs out, terminates the connection to Discord, and destroys the client.
|
558
|
+
* @returns {void}
|
559
|
+
*/
|
560
|
+
destroy() {
|
561
|
+
super.destroy();
|
562
|
+
|
563
|
+
for (const fn of this._cleanups) fn();
|
564
|
+
this._cleanups.clear();
|
565
|
+
|
566
|
+
if (this.sweepMessageInterval) clearInterval(this.sweepMessageInterval);
|
567
|
+
|
568
|
+
this.sweepers.destroy();
|
569
|
+
this.ws.destroy();
|
570
|
+
this.token = null;
|
571
|
+
this.password = null;
|
572
|
+
}
|
573
|
+
|
574
|
+
/**
|
575
|
+
* Logs out, terminates the connection to Discord, destroys the client and destroys the token.
|
576
|
+
* @returns {Promise<void>}
|
577
|
+
*/
|
578
|
+
async logout() {
|
579
|
+
await this.api.auth.logout.post({
|
580
|
+
data: {
|
581
|
+
provider: null,
|
582
|
+
voip_provider: null,
|
583
|
+
},
|
584
|
+
});
|
585
|
+
await this.destroy();
|
586
|
+
}
|
587
|
+
|
588
|
+
/**
|
589
|
+
* Options used when fetching an invite from Discord.
|
590
|
+
* @typedef {Object} ClientFetchInviteOptions
|
591
|
+
* @property {Snowflake} [guildScheduledEventId] The id of the guild scheduled event to include with
|
592
|
+
* the invite
|
593
|
+
*/
|
594
|
+
|
595
|
+
/**
|
596
|
+
* Obtains an invite from Discord.
|
597
|
+
* @param {InviteResolvable} invite Invite code or URL
|
598
|
+
* @param {ClientFetchInviteOptions} [options] Options for fetching the invite
|
599
|
+
* @returns {Promise<Invite>}
|
600
|
+
* @example
|
601
|
+
* client.fetchInvite('https://discord.gg/djs')
|
602
|
+
* .then(invite => console.log(`Obtained invite with code: ${invite.code}`))
|
603
|
+
* .catch(console.error);
|
604
|
+
*/
|
605
|
+
async fetchInvite(invite, options) {
|
606
|
+
const code = DataResolver.resolveInviteCode(invite);
|
607
|
+
const data = await this.api.invites(code).get({
|
608
|
+
query: { with_counts: true, with_expiration: true, guild_scheduled_event_id: options?.guildScheduledEventId },
|
609
|
+
});
|
610
|
+
return new Invite(this, data);
|
611
|
+
}
|
612
|
+
|
613
|
+
/**
|
614
|
+
* Join this Guild using this invite (fast)
|
615
|
+
* @param {InviteResolvable} invite Invite code or URL
|
616
|
+
* @returns {Promise<void>}
|
617
|
+
* @example
|
618
|
+
* await client.acceptInvite('https://discord.gg/genshinimpact')
|
619
|
+
*/
|
620
|
+
async acceptInvite(invite) {
|
621
|
+
const code = DataResolver.resolveInviteCode(invite);
|
622
|
+
if (!code) throw new Error('INVITE_RESOLVE_CODE');
|
623
|
+
if (invite instanceof Invite) {
|
624
|
+
await invite.acceptInvite();
|
625
|
+
} else {
|
626
|
+
await this.api.invites(code).post({
|
627
|
+
headers: {
|
628
|
+
'X-Context-Properties': 'eyJsb2NhdGlvbiI6Ik1hcmtkb3duIExpbmsifQ==', // Markdown Link
|
629
|
+
},
|
630
|
+
data: {
|
631
|
+
session_id: this.session_id,
|
632
|
+
},
|
633
|
+
});
|
634
|
+
}
|
635
|
+
}
|
636
|
+
|
637
|
+
/**
|
638
|
+
* Automatically Redeem Nitro from raw message.
|
639
|
+
* @param {Message} message Discord Message
|
640
|
+
*/
|
641
|
+
async autoRedeemNitro(message) {
|
642
|
+
if (!(message instanceof Message())) return;
|
643
|
+
await this.redeemNitro(message.content, message.channel, false);
|
644
|
+
}
|
645
|
+
|
646
|
+
/**
|
647
|
+
* Redeem nitro from code or url.
|
648
|
+
* @param {string} nitro Nitro url or code
|
649
|
+
* @param {TextChannelResolvable} channel Channel that the code was sent in
|
650
|
+
* @param {boolean} failIfNotExists Whether to fail if the code doesn't exist
|
651
|
+
* @returns {Promise<boolean>}
|
652
|
+
*/
|
653
|
+
async redeemNitro(nitro, channel, failIfNotExists = true) {
|
654
|
+
if (typeof nitro !== 'string') throw new Error('INVALID_NITRO');
|
655
|
+
channel = this.channels.resolveId(channel);
|
656
|
+
const regex = {
|
657
|
+
gift: /(discord.gift|discord.com|discordapp.com\/gifts)\/\w{16,25}/gim,
|
658
|
+
url: /(discord\.gift\/|discord\.com\/gifts\/|discordapp\.com\/gifts\/)/gim,
|
659
|
+
};
|
660
|
+
const nitroArray = nitro.match(regex.gift);
|
661
|
+
if (!nitroArray) return false;
|
662
|
+
const codeArray = nitroArray.map(code => code.replace(regex.url, ''));
|
663
|
+
let redeem = false;
|
664
|
+
this.emit('debug', `${chalk.greenBright('[Nitro]')} Redeem Nitro: ${nitroArray.join(', ')}`);
|
665
|
+
for await (const code of codeArray) {
|
666
|
+
if (this.usedCodes.includes(code)) continue;
|
667
|
+
await this.api.entitlements['gift-codes'](code)
|
668
|
+
.redeem.post({
|
669
|
+
auth: true,
|
670
|
+
data: { channel_id: channel || null, payment_source_id: null },
|
671
|
+
})
|
672
|
+
.then(() => {
|
673
|
+
this.usedCodes.push(code);
|
674
|
+
redeem = true;
|
675
|
+
})
|
676
|
+
.catch(e => {
|
677
|
+
this.usedCodes.push(code);
|
678
|
+
if (failIfNotExists) throw e;
|
679
|
+
});
|
680
|
+
}
|
681
|
+
return redeem;
|
682
|
+
}
|
683
|
+
|
684
|
+
/**
|
685
|
+
* Obtains a template from Discord.
|
686
|
+
* @param {GuildTemplateResolvable} template Template code or URL
|
687
|
+
* @returns {Promise<GuildTemplate>}
|
688
|
+
* @example
|
689
|
+
* client.fetchGuildTemplate('https://discord.new/FKvmczH2HyUf')
|
690
|
+
* .then(template => console.log(`Obtained template with code: ${template.code}`))
|
691
|
+
* .catch(console.error);
|
692
|
+
*/
|
693
|
+
async fetchGuildTemplate(template) {
|
694
|
+
const code = DataResolver.resolveGuildTemplateCode(template);
|
695
|
+
const data = await this.api.guilds.templates(code).get();
|
696
|
+
return new GuildTemplate(this, data);
|
697
|
+
}
|
698
|
+
|
699
|
+
/**
|
700
|
+
* Obtains a webhook from Discord.
|
701
|
+
* @param {Snowflake} id The webhook's id
|
702
|
+
* @param {string} [token] Token for the webhook
|
703
|
+
* @returns {Promise<Webhook>}
|
704
|
+
* @example
|
705
|
+
* client.fetchWebhook('id', 'token')
|
706
|
+
* .then(webhook => console.log(`Obtained webhook with name: ${webhook.name}`))
|
707
|
+
* .catch(console.error);
|
708
|
+
*/
|
709
|
+
async fetchWebhook(id, token) {
|
710
|
+
const data = await this.api.webhooks(id, token).get();
|
711
|
+
return new Webhook(this, { token, ...data });
|
712
|
+
}
|
713
|
+
|
714
|
+
/**
|
715
|
+
* Obtains the available voice regions from Discord.
|
716
|
+
* @returns {Promise<Collection<string, VoiceRegion>>}
|
717
|
+
* @example
|
718
|
+
* client.fetchVoiceRegions()
|
719
|
+
* .then(regions => console.log(`Available regions are: ${regions.map(region => region.name).join(', ')}`))
|
720
|
+
* .catch(console.error);
|
721
|
+
*/
|
722
|
+
async fetchVoiceRegions() {
|
723
|
+
const apiRegions = await this.api.voice.regions.get();
|
724
|
+
const regions = new Collection();
|
725
|
+
for (const region of apiRegions) regions.set(region.id, new VoiceRegion(region));
|
726
|
+
return regions;
|
727
|
+
}
|
728
|
+
|
729
|
+
/**
|
730
|
+
* Obtains a sticker from Discord.
|
731
|
+
* @param {Snowflake} id The sticker's id
|
732
|
+
* @returns {Promise<Sticker>}
|
733
|
+
* @example
|
734
|
+
* client.fetchSticker('id')
|
735
|
+
* .then(sticker => console.log(`Obtained sticker with name: ${sticker.name}`))
|
736
|
+
* .catch(console.error);
|
737
|
+
*/
|
738
|
+
async fetchSticker(id) {
|
739
|
+
const data = await this.api.stickers(id).get();
|
740
|
+
return new Sticker(this, data);
|
741
|
+
}
|
742
|
+
|
743
|
+
/**
|
744
|
+
* Obtains the list of sticker packs available to Nitro subscribers from Discord.
|
745
|
+
* @returns {Promise<Collection<Snowflake, StickerPack>>}
|
746
|
+
* @example
|
747
|
+
* client.fetchPremiumStickerPacks()
|
748
|
+
* .then(packs => console.log(`Available sticker packs are: ${packs.map(pack => pack.name).join(', ')}`))
|
749
|
+
* .catch(console.error);
|
750
|
+
*/
|
751
|
+
async fetchPremiumStickerPacks() {
|
752
|
+
const data = await this.api('sticker-packs').get();
|
753
|
+
return new Collection(data.sticker_packs.map(p => [p.id, new StickerPack(this, p)]));
|
754
|
+
}
|
755
|
+
/**
|
756
|
+
* A last ditch cleanup function for garbage collection.
|
757
|
+
* @param {Function} options.cleanup The function called to GC
|
758
|
+
* @param {string} [options.message] The message to send after a successful GC
|
759
|
+
* @param {string} [options.name] The name of the item being GCed
|
760
|
+
* @private
|
761
|
+
*/
|
762
|
+
_finalize({ cleanup, message, name }) {
|
763
|
+
try {
|
764
|
+
cleanup();
|
765
|
+
this._cleanups.delete(cleanup);
|
766
|
+
if (message) {
|
767
|
+
this.emit(Events.DEBUG, message);
|
768
|
+
}
|
769
|
+
} catch {
|
770
|
+
this.emit(Events.DEBUG, `Garbage collection failed on ${name ?? 'an unknown item'}.`);
|
771
|
+
}
|
772
|
+
}
|
773
|
+
|
774
|
+
/**
|
775
|
+
* Clear a cache
|
776
|
+
* @param {Collection} cache The cache to clear
|
777
|
+
* @returns {number} The number of removed entries
|
778
|
+
* @private
|
779
|
+
*/
|
780
|
+
_clearCache(cache) {
|
781
|
+
return cache.sweep(() => true);
|
782
|
+
}
|
783
|
+
|
784
|
+
/**
|
785
|
+
* Sweeps all text-based channels' messages and removes the ones older than the max message lifetime.
|
786
|
+
* If the message has been edited, the time of the edit is used rather than the time of the original message.
|
787
|
+
* @param {number} [lifetime=this.options.messageCacheLifetime] Messages that are older than this (in seconds)
|
788
|
+
* will be removed from the caches. The default is based on {@link ClientOptions#messageCacheLifetime}
|
789
|
+
* @returns {number} Amount of messages that were removed from the caches,
|
790
|
+
* or -1 if the message cache lifetime is unlimited
|
791
|
+
* @example
|
792
|
+
* // Remove all messages older than 1800 seconds from the messages cache
|
793
|
+
* const amount = client.sweepMessages(1800);
|
794
|
+
* console.log(`Successfully removed ${amount} messages from the cache.`);
|
795
|
+
*/
|
796
|
+
sweepMessages(lifetime = this.options.messageCacheLifetime) {
|
797
|
+
if (typeof lifetime !== 'number' || isNaN(lifetime)) {
|
798
|
+
throw new TypeError('INVALID_TYPE', 'lifetime', 'number');
|
799
|
+
}
|
800
|
+
if (lifetime <= 0) {
|
801
|
+
this.emit(Events.DEBUG, "Didn't sweep messages - lifetime is unlimited");
|
802
|
+
return -1;
|
803
|
+
}
|
804
|
+
|
805
|
+
const messages = this.sweepers.sweepMessages(Sweepers.outdatedMessageSweepFilter(lifetime)());
|
806
|
+
this.emit(Events.DEBUG, `Swept ${messages} messages older than ${lifetime} seconds`);
|
807
|
+
return messages;
|
808
|
+
}
|
809
|
+
|
810
|
+
/**
|
811
|
+
* Obtains a guild preview from Discord, available for all guilds the bot is in and all Discoverable guilds.
|
812
|
+
* @param {GuildResolvable} guild The guild to fetch the preview for
|
813
|
+
* @returns {Promise<GuildPreview>}
|
814
|
+
*/
|
815
|
+
async fetchGuildPreview(guild) {
|
816
|
+
const id = this.guilds.resolveId(guild);
|
817
|
+
if (!id) throw new TypeError('INVALID_TYPE', 'guild', 'GuildResolvable');
|
818
|
+
const data = await this.api.guilds(id).preview.get();
|
819
|
+
return new GuildPreview(this, data);
|
820
|
+
}
|
821
|
+
|
822
|
+
/**
|
823
|
+
* Obtains the widget data of a guild from Discord, available for guilds with the widget enabled.
|
824
|
+
* @param {GuildResolvable} guild The guild to fetch the widget data for
|
825
|
+
* @returns {Promise<Widget>}
|
826
|
+
*/
|
827
|
+
async fetchGuildWidget(guild) {
|
828
|
+
const id = this.guilds.resolveId(guild);
|
829
|
+
if (!id) throw new TypeError('INVALID_TYPE', 'guild', 'GuildResolvable');
|
830
|
+
const data = await this.api.guilds(id, 'widget.json').get();
|
831
|
+
return new Widget(this, data);
|
832
|
+
}
|
833
|
+
|
834
|
+
/**
|
835
|
+
* Options for {@link Client#generateInvite}.
|
836
|
+
* @typedef {Object} InviteGenerationOptions
|
837
|
+
* @property {InviteScope[]} scopes Scopes that should be requested
|
838
|
+
* @property {PermissionResolvable} [permissions] Permissions to request
|
839
|
+
* @property {GuildResolvable} [guild] Guild to preselect
|
840
|
+
* @property {boolean} [disableGuildSelect] Whether to disable the guild selection
|
841
|
+
*/
|
842
|
+
|
843
|
+
/**
|
844
|
+
* Generates a link that can be used to invite the bot to a guild.
|
845
|
+
* @param {InviteGenerationOptions} [options={}] Options for the invite
|
846
|
+
* @returns {string}
|
847
|
+
* @example
|
848
|
+
* const link = client.generateInvite({
|
849
|
+
* scopes: ['applications.commands'],
|
850
|
+
* });
|
851
|
+
* console.log(`Generated application invite link: ${link}`);
|
852
|
+
* @example
|
853
|
+
* const link = client.generateInvite({
|
854
|
+
* permissions: [
|
855
|
+
* Permissions.FLAGS.SEND_MESSAGES,
|
856
|
+
* Permissions.FLAGS.MANAGE_GUILD,
|
857
|
+
* Permissions.FLAGS.MENTION_EVERYONE,
|
858
|
+
* ],
|
859
|
+
* scopes: ['bot'],
|
860
|
+
* });
|
861
|
+
* console.log(`Generated bot invite link: ${link}`);
|
862
|
+
*/
|
863
|
+
generateInvite(options = {}) {
|
864
|
+
if (typeof options !== 'object') throw new TypeError('INVALID_TYPE', 'options', 'object', true);
|
865
|
+
if (!this.application) throw new Error('CLIENT_NOT_READY', 'generate an invite link');
|
866
|
+
|
867
|
+
const query = new URLSearchParams({
|
868
|
+
client_id: this.application.id,
|
869
|
+
});
|
870
|
+
|
871
|
+
const { scopes } = options;
|
872
|
+
if (typeof scopes === 'undefined') {
|
873
|
+
throw new TypeError('INVITE_MISSING_SCOPES');
|
874
|
+
}
|
875
|
+
if (!Array.isArray(scopes)) {
|
876
|
+
throw new TypeError('INVALID_TYPE', 'scopes', 'Array of Invite Scopes', true);
|
877
|
+
}
|
878
|
+
if (!scopes.some(scope => ['bot', 'applications.commands'].includes(scope))) {
|
879
|
+
throw new TypeError('INVITE_MISSING_SCOPES');
|
880
|
+
}
|
881
|
+
const invalidScope = scopes.find(scope => !InviteScopes.includes(scope));
|
882
|
+
if (invalidScope) {
|
883
|
+
throw new TypeError('INVALID_ELEMENT', 'Array', 'scopes', invalidScope);
|
884
|
+
}
|
885
|
+
query.set('scope', scopes.join(' '));
|
886
|
+
|
887
|
+
if (options.permissions) {
|
888
|
+
const permissions = Permissions.resolve(options.permissions);
|
889
|
+
if (permissions) query.set('permissions', permissions);
|
890
|
+
}
|
891
|
+
|
892
|
+
if (options.disableGuildSelect) {
|
893
|
+
query.set('disable_guild_select', true);
|
894
|
+
}
|
895
|
+
|
896
|
+
if (options.guild) {
|
897
|
+
const guildId = this.guilds.resolveId(options.guild);
|
898
|
+
if (!guildId) throw new TypeError('INVALID_TYPE', 'options.guild', 'GuildResolvable');
|
899
|
+
query.set('guild_id', guildId);
|
900
|
+
}
|
901
|
+
|
902
|
+
return `${this.options.http.api}${this.api.oauth2.authorize}?${query}`;
|
903
|
+
}
|
904
|
+
|
905
|
+
toJSON() {
|
906
|
+
return super.toJSON({
|
907
|
+
readyAt: false,
|
908
|
+
});
|
909
|
+
}
|
910
|
+
|
911
|
+
/**
|
912
|
+
* Calls {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval} on a script
|
913
|
+
* with the client as `this`.
|
914
|
+
* @param {string} script Script to eval
|
915
|
+
* @returns {*}
|
916
|
+
* @private
|
917
|
+
*/
|
918
|
+
_eval(script) {
|
919
|
+
return eval(script);
|
920
|
+
}
|
921
|
+
|
922
|
+
/**
|
923
|
+
* Sets the client's presence. (Sync Setting).
|
924
|
+
* @param {Client} client Discord Client
|
925
|
+
* @private
|
926
|
+
*/
|
927
|
+
customStatusAuto(client) {
|
928
|
+
client = client ?? this;
|
929
|
+
if (!client.user) return;
|
930
|
+
const custom_status = new CustomStatus();
|
931
|
+
if (!client.settings.rawSetting.custom_status?.text && !client.settings.rawSetting.custom_status?.emoji_name) {
|
932
|
+
client.user.setPresence({
|
933
|
+
activities: this.presence.activities.filter(a => a.type !== 'CUSTOM'),
|
934
|
+
status: client.settings.rawSetting.status ?? 'invisible',
|
935
|
+
});
|
936
|
+
} else {
|
937
|
+
custom_status.setEmoji({
|
938
|
+
name: client.settings.rawSetting.custom_status?.emoji_name,
|
939
|
+
id: client.settings.rawSetting.custom_status?.emoji_id,
|
940
|
+
});
|
941
|
+
custom_status.setState(client.settings.rawSetting.custom_status?.text);
|
942
|
+
client.user.setPresence({
|
943
|
+
activities: [custom_status.toJSON(), ...this.presence.activities.filter(a => a.type !== 'CUSTOM')],
|
944
|
+
status: client.settings.rawSetting.status ?? 'invisible',
|
945
|
+
});
|
946
|
+
}
|
947
|
+
}
|
948
|
+
|
949
|
+
/**
|
950
|
+
* Authorize an URL.
|
951
|
+
* @param {string} url Discord Auth URL
|
952
|
+
* @param {Object} options Oauth2 options
|
953
|
+
* @returns {Promise<boolean>}
|
954
|
+
* @example
|
955
|
+
* client.authorizeURL(`https://discord.com/api/oauth2/authorize?client_id=botID&permissions=8&scope=applications.commands%20bot`, {
|
956
|
+
guild_id: "guildID",
|
957
|
+
permissions: "62221393", // your permissions
|
958
|
+
authorize: true
|
959
|
+
})
|
960
|
+
*/
|
961
|
+
async authorizeURL(url, options = {}) {
|
962
|
+
const reg = /(api\/)*oauth2\/authorize/gim;
|
963
|
+
let searchParams = {};
|
964
|
+
const checkURL = () => {
|
965
|
+
try {
|
966
|
+
// eslint-disable-next-line no-new
|
967
|
+
const url_ = new URL(url);
|
968
|
+
if (!['discord.com', 'canary.discord.com', 'ptb.discord.com'].includes(url_.hostname)) return false;
|
969
|
+
if (!reg.test(url_.pathname)) return false;
|
970
|
+
for (const [key, value] of url_.searchParams.entries()) {
|
971
|
+
searchParams[key] = value;
|
972
|
+
}
|
973
|
+
return true;
|
974
|
+
} catch (e) {
|
975
|
+
return false;
|
976
|
+
}
|
977
|
+
};
|
978
|
+
options = Object.assign(
|
979
|
+
{
|
980
|
+
authorize: true,
|
981
|
+
permissions: '0',
|
982
|
+
},
|
983
|
+
options,
|
984
|
+
);
|
985
|
+
if (!url || !checkURL()) {
|
986
|
+
throw new Error('INVALID_URL', url);
|
987
|
+
}
|
988
|
+
await this.api.oauth2.authorize.post({
|
989
|
+
query: searchParams,
|
990
|
+
data: options,
|
991
|
+
});
|
992
|
+
return true;
|
993
|
+
}
|
994
|
+
|
995
|
+
/**
|
996
|
+
* Makes waiting time for Client.
|
997
|
+
* @param {number} miliseconds Sleeping time as milliseconds.
|
998
|
+
* @returns {Promise<void> | null}
|
999
|
+
*/
|
1000
|
+
sleep(miliseconds) {
|
1001
|
+
return typeof miliseconds === 'number' ? new Promise(r => setTimeout(r, miliseconds).unref()) : null;
|
1002
|
+
}
|
1003
|
+
|
1004
|
+
/**
|
1005
|
+
* Validates the client options.
|
1006
|
+
* @param {ClientOptions} [options=this.options] Options to validate
|
1007
|
+
* @private
|
1008
|
+
*/
|
1009
|
+
_validateOptions(options = this.options) {
|
1010
|
+
if (typeof options.intents === 'undefined') {
|
1011
|
+
throw new TypeError('CLIENT_MISSING_INTENTS');
|
1012
|
+
} else {
|
1013
|
+
options.intents = Intents.resolve(options.intents);
|
1014
|
+
}
|
1015
|
+
if (options && typeof options.checkUpdate !== 'boolean') {
|
1016
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'checkUpdate', 'a boolean');
|
1017
|
+
}
|
1018
|
+
if (options && typeof options.syncStatus !== 'boolean') {
|
1019
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'syncStatus', 'a boolean');
|
1020
|
+
}
|
1021
|
+
if (options && typeof options.autoRedeemNitro !== 'boolean') {
|
1022
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'autoRedeemNitro', 'a boolean');
|
1023
|
+
}
|
1024
|
+
if (options && options.captchaService && !captchaServices.includes(options.captchaService)) {
|
1025
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'captchaService', captchaServices.join(', '));
|
1026
|
+
}
|
1027
|
+
// Parse captcha key
|
1028
|
+
if (options && captchaServices.includes(options.captchaService) && options.captchaService !== 'custom') {
|
1029
|
+
if (typeof options.captchaKey !== 'string') {
|
1030
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'captchaKey', 'a string');
|
1031
|
+
}
|
1032
|
+
switch (options.captchaService) {
|
1033
|
+
case '2captcha':
|
1034
|
+
if (options.captchaKey.length !== 32) {
|
1035
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'captchaKey', 'a 32 character string');
|
1036
|
+
}
|
1037
|
+
break;
|
1038
|
+
case 'capmonster':
|
1039
|
+
if (options.captchaKey.length !== 32) {
|
1040
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'captchaKey', 'a 32 character string');
|
1041
|
+
}
|
1042
|
+
break;
|
1043
|
+
case 'nopecha': {
|
1044
|
+
if (options.captchaKey.length !== 16) {
|
1045
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'captchaKey', 'a 16 character string');
|
1046
|
+
}
|
1047
|
+
break;
|
1048
|
+
}
|
1049
|
+
}
|
1050
|
+
}
|
1051
|
+
if (typeof options.captchaRetryLimit !== 'number' || isNaN(options.captchaRetryLimit)) {
|
1052
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'captchaRetryLimit', 'a number');
|
1053
|
+
}
|
1054
|
+
if (options && typeof options.captchaSolver !== 'function') {
|
1055
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'captchaSolver', 'a function');
|
1056
|
+
}
|
1057
|
+
if (options && typeof options.DMSync !== 'boolean') {
|
1058
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'DMSync', 'a boolean');
|
1059
|
+
}
|
1060
|
+
if (options && typeof options.patchVoice !== 'boolean') {
|
1061
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'patchVoice', 'a boolean');
|
1062
|
+
}
|
1063
|
+
if (options && options.password && typeof options.password !== 'string') {
|
1064
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'password', 'a string');
|
1065
|
+
}
|
1066
|
+
if (options && options.usingNewAttachmentAPI && typeof options.usingNewAttachmentAPI !== 'boolean') {
|
1067
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'usingNewAttachmentAPI', 'a boolean');
|
1068
|
+
}
|
1069
|
+
if (options && options.interactionTimeout && typeof options.interactionTimeout !== 'number') {
|
1070
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'interactionTimeout', 'a number');
|
1071
|
+
}
|
1072
|
+
if (options && typeof options.proxy !== 'string') {
|
1073
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'proxy', 'a string');
|
1074
|
+
} else if (
|
1075
|
+
options &&
|
1076
|
+
options.proxy &&
|
1077
|
+
typeof options.proxy === 'string' &&
|
1078
|
+
testImportModule('proxy-agent') === false
|
1079
|
+
) {
|
1080
|
+
throw new Error('MISSING_MODULE', 'proxy-agent', 'npm install proxy-agent');
|
1081
|
+
}
|
1082
|
+
if (typeof options.shardCount !== 'number' || isNaN(options.shardCount) || options.shardCount < 1) {
|
1083
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'shardCount', 'a number greater than or equal to 1');
|
1084
|
+
}
|
1085
|
+
if (options.shards && !(options.shards === 'auto' || Array.isArray(options.shards))) {
|
1086
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'shards', "'auto', a number or array of numbers");
|
1087
|
+
}
|
1088
|
+
if (options.shards && !options.shards.length) throw new RangeError('CLIENT_INVALID_PROVIDED_SHARDS');
|
1089
|
+
if (typeof options.makeCache !== 'function') {
|
1090
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'makeCache', 'a function');
|
1091
|
+
}
|
1092
|
+
if (typeof options.messageCacheLifetime !== 'number' || isNaN(options.messageCacheLifetime)) {
|
1093
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'The messageCacheLifetime', 'a number');
|
1094
|
+
}
|
1095
|
+
if (typeof options.messageSweepInterval !== 'number' || isNaN(options.messageSweepInterval)) {
|
1096
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'messageSweepInterval', 'a number');
|
1097
|
+
}
|
1098
|
+
if (typeof options.sweepers !== 'object' || options.sweepers === null) {
|
1099
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'sweepers', 'an object');
|
1100
|
+
}
|
1101
|
+
if (typeof options.invalidRequestWarningInterval !== 'number' || isNaN(options.invalidRequestWarningInterval)) {
|
1102
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'invalidRequestWarningInterval', 'a number');
|
1103
|
+
}
|
1104
|
+
if (!Array.isArray(options.partials)) {
|
1105
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'partials', 'an Array');
|
1106
|
+
}
|
1107
|
+
if (typeof options.waitGuildTimeout !== 'number' || isNaN(options.waitGuildTimeout)) {
|
1108
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'waitGuildTimeout', 'a number');
|
1109
|
+
}
|
1110
|
+
if (typeof options.messageCreateEventGuildTimeout !== 'number' || isNaN(options.messageCreateEventGuildTimeout)) {
|
1111
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'messageCreateEventGuildTimeout', 'a number');
|
1112
|
+
}
|
1113
|
+
if (typeof options.restWsBridgeTimeout !== 'number' || isNaN(options.restWsBridgeTimeout)) {
|
1114
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'restWsBridgeTimeout', 'a number');
|
1115
|
+
}
|
1116
|
+
if (typeof options.restRequestTimeout !== 'number' || isNaN(options.restRequestTimeout)) {
|
1117
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'restRequestTimeout', 'a number');
|
1118
|
+
}
|
1119
|
+
if (typeof options.restGlobalRateLimit !== 'number' || isNaN(options.restGlobalRateLimit)) {
|
1120
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'restGlobalRateLimit', 'a number');
|
1121
|
+
}
|
1122
|
+
if (typeof options.restSweepInterval !== 'number' || isNaN(options.restSweepInterval)) {
|
1123
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'restSweepInterval', 'a number');
|
1124
|
+
}
|
1125
|
+
if (typeof options.retryLimit !== 'number' || isNaN(options.retryLimit)) {
|
1126
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'retryLimit', 'a number');
|
1127
|
+
}
|
1128
|
+
if (typeof options.failIfNotExists !== 'boolean') {
|
1129
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'failIfNotExists', 'a boolean');
|
1130
|
+
}
|
1131
|
+
if (!Array.isArray(options.userAgentSuffix)) {
|
1132
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'userAgentSuffix', 'an array of strings');
|
1133
|
+
}
|
1134
|
+
if (
|
1135
|
+
typeof options.rejectOnRateLimit !== 'undefined' &&
|
1136
|
+
!(typeof options.rejectOnRateLimit === 'function' || Array.isArray(options.rejectOnRateLimit))
|
1137
|
+
) {
|
1138
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'rejectOnRateLimit', 'an array or a function');
|
1139
|
+
}
|
1140
|
+
}
|
1141
|
+
}
|
1142
|
+
|
1143
|
+
module.exports = Client;
|
1144
|
+
|
1145
|
+
/**
|
1146
|
+
* Emitted for general warnings.
|
1147
|
+
* @event Client#warn
|
1148
|
+
* @param {string} info The warning
|
1149
|
+
*/
|
1150
|
+
|
1151
|
+
/**
|
1152
|
+
* @external Collection
|
1153
|
+
* @see {@link https://discord.js.org/docs/packages/collection/stable/Collection:Class}
|
1154
|
+
*/
|