discord.js-seflbot-v13 1.1.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.js-seflbot-v13 might be problematic. Click here for more details.
- package/LICENSE +674 -0
- package/README.md +128 -0
- package/package.json +103 -0
- package/src/WebSocket.js +39 -0
- package/src/client/BaseClient.js +87 -0
- package/src/client/Client.js +1102 -0
- package/src/client/WebhookClient.js +61 -0
- package/src/client/actions/Action.js +120 -0
- package/src/client/actions/ActionsManager.js +78 -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 +43 -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 +61 -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 +905 -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 +53 -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_SOUNDBOARD_SOUNDS_UPDATE.js +0 -0
- package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_CREATE.js +0 -0
- package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_DELETE.js +0 -0
- package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_UPDATE.js +0 -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 +171 -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/SOUNDBOARD_SOUNDS.js +0 -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_REQUIRED_ACTION_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_CHANNEL_EFFECT_SEND.js +0 -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 +87 -0
- package/src/errors/DJSError.js +61 -0
- package/src/errors/Messages.js +228 -0
- package/src/errors/index.js +4 -0
- package/src/index.js +194 -0
- package/src/main.js +1 -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 +504 -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 +772 -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 +133 -0
- package/src/rest/APIRouter.js +53 -0
- package/src/rest/CaptchaSolver.js +139 -0
- package/src/rest/DiscordAPIError.js +103 -0
- package/src/rest/HTTPError.js +62 -0
- package/src/rest/RESTManager.js +82 -0
- package/src/rest/RateLimitError.js +55 -0
- package/src/rest/RequestHandler.js +430 -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 +1030 -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 +203 -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 +85 -0
- package/src/structures/Channel.js +271 -0
- package/src/structures/ClientApplication.js +233 -0
- package/src/structures/ClientPresence.js +92 -0
- package/src/structures/ClientUser.js +635 -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 +289 -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 +468 -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 +204 -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 +449 -0
- package/src/structures/PermissionOverwrites.js +196 -0
- package/src/structures/Presence.js +443 -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 +531 -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 +730 -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 +353 -0
- package/src/structures/WebEmbed.js +412 -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 +76 -0
- package/src/util/AttachmentFlags.js +38 -0
- package/src/util/BitField.js +170 -0
- package/src/util/ChannelFlags.js +45 -0
- package/src/util/Constants.js +1940 -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 +364 -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 +514 -0
- package/src/util/RoleFlags.js +37 -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 +882 -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 +7776 -0
- package/typings/index.test-d.ts +0 -0
- package/typings/rawDataTypes.d.ts +283 -0
@@ -0,0 +1,1102 @@
|
|
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 chalk = require('chalk');
|
8
|
+
const fetch = require('node-fetch');
|
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 { testImportModule } = require('../util/Util');
|
44
|
+
const phin = require('phin');
|
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
|
+
if (this.options.messageSweepInterval > 0) {
|
244
|
+
process.emitWarning(
|
245
|
+
'The message sweeping client options are deprecated, use the global sweepers instead.',
|
246
|
+
'DeprecationWarning',
|
247
|
+
);
|
248
|
+
this.sweepMessageInterval = setInterval(
|
249
|
+
this.sweepMessages.bind(this),
|
250
|
+
this.options.messageSweepInterval * 1_000,
|
251
|
+
).unref();
|
252
|
+
}
|
253
|
+
}
|
254
|
+
|
255
|
+
/**
|
256
|
+
* Session ID
|
257
|
+
* @type {?string}
|
258
|
+
* @readonly
|
259
|
+
*/
|
260
|
+
get sessionId() {
|
261
|
+
return this.ws.shards.first()?.sessionId;
|
262
|
+
}
|
263
|
+
|
264
|
+
/**
|
265
|
+
* All custom emojis that the client has access to, mapped by their ids
|
266
|
+
* @type {BaseGuildEmojiManager}
|
267
|
+
* @readonly
|
268
|
+
*/
|
269
|
+
get emojis() {
|
270
|
+
const emojis = new BaseGuildEmojiManager(this);
|
271
|
+
for (const guild of this.guilds.cache.values()) {
|
272
|
+
if (guild.available) for (const emoji of guild.emojis.cache.values()) emojis.cache.set(emoji.id, emoji);
|
273
|
+
}
|
274
|
+
return emojis;
|
275
|
+
}
|
276
|
+
|
277
|
+
/**
|
278
|
+
* Timestamp of the time the client was last `READY` at
|
279
|
+
* @type {?number}
|
280
|
+
* @readonly
|
281
|
+
*/
|
282
|
+
get readyTimestamp() {
|
283
|
+
return this.readyAt?.getTime() ?? null;
|
284
|
+
}
|
285
|
+
|
286
|
+
/**
|
287
|
+
* How long it has been since the client last entered the `READY` state in milliseconds
|
288
|
+
* @type {?number}
|
289
|
+
* @readonly
|
290
|
+
*/
|
291
|
+
get uptime() {
|
292
|
+
return this.readyAt ? Date.now() - this.readyAt : null;
|
293
|
+
}
|
294
|
+
|
295
|
+
/**
|
296
|
+
* @external VoiceConnection
|
297
|
+
* @see {@link https://discord.js.org/#/docs/voice/main/class/VoiceConnection}
|
298
|
+
*/
|
299
|
+
/**
|
300
|
+
* Get connection to current call
|
301
|
+
* @type {?VoiceConnection}
|
302
|
+
* @readonly
|
303
|
+
*/
|
304
|
+
get callVoice() {
|
305
|
+
return getVoiceConnection(null);
|
306
|
+
}
|
307
|
+
|
308
|
+
/**
|
309
|
+
* Logs the client in, establishing a WebSocket connection to Discord.
|
310
|
+
* @param {string} [token=this.token] Token of the account to log in with
|
311
|
+
* @returns {Promise<string>} Token of the account used
|
312
|
+
* @example
|
313
|
+
* client.login('my token');
|
314
|
+
*/
|
315
|
+
async login(token = this.token) {
|
316
|
+
if (!token || typeof token !== 'string') throw new Error('TOKEN_INVALID');
|
317
|
+
this.token = token = token.replace(/^(Bot|Bearer)\s*/i, '');
|
318
|
+
this.emit(
|
319
|
+
Events.DEBUG,
|
320
|
+
`
|
321
|
+
Logging on with a user token is unfortunately against the Discord
|
322
|
+
\`Terms of Service\` <https://support.discord.com/hc/en-us/articles/115002192352>
|
323
|
+
and doing so might potentially get your account banned.
|
324
|
+
Use this at your own risk.
|
325
|
+
`,
|
326
|
+
);
|
327
|
+
this.emit(
|
328
|
+
Events.DEBUG,
|
329
|
+
`Provided token: ${token
|
330
|
+
.split('.')
|
331
|
+
.map((val, i) => (i > 1 ? val.replace(/./g, '*') : val))
|
332
|
+
.join('.')}`,
|
333
|
+
);
|
334
|
+
|
335
|
+
if (this.options.presence) {
|
336
|
+
this.options.ws.presence = this.presence._parse(this.options.presence);
|
337
|
+
}
|
338
|
+
|
339
|
+
this.emit(Events.DEBUG, 'Preparing to connect to the gateway...');
|
340
|
+
|
341
|
+
try {
|
342
|
+
await this.ws.connect();
|
343
|
+
return this.token;
|
344
|
+
} catch (error) {
|
345
|
+
this.destroy();
|
346
|
+
throw error;
|
347
|
+
}
|
348
|
+
}
|
349
|
+
|
350
|
+
/**
|
351
|
+
* Login Discord with Username and Password
|
352
|
+
* @param {string} username Email or Phone Number
|
353
|
+
* @param {?string} password Password
|
354
|
+
* @param {?string} mfaCode 2FA Code / Backup Code
|
355
|
+
* @returns {Promise<string>}
|
356
|
+
*/
|
357
|
+
async normalLogin(username, password = this.password, mfaCode) {
|
358
|
+
if (!username || !password || typeof username !== 'string' || typeof password !== 'string') {
|
359
|
+
throw new Error('NORMAL_LOGIN');
|
360
|
+
}
|
361
|
+
this.emit(
|
362
|
+
Events.DEBUG,
|
363
|
+
`Connecting to Discord with:
|
364
|
+
username: ${username}
|
365
|
+
password: ${password.replace(/./g, '*')}`,
|
366
|
+
);
|
367
|
+
const data = await this.api.auth.login.post({
|
368
|
+
data: {
|
369
|
+
login: username,
|
370
|
+
password: password,
|
371
|
+
undelete: false,
|
372
|
+
captcha_key: null,
|
373
|
+
login_source: null,
|
374
|
+
gift_code_sku_id: null,
|
375
|
+
},
|
376
|
+
auth: false,
|
377
|
+
});
|
378
|
+
this.password = password;
|
379
|
+
if (!data.token && data.ticket && data.mfa) {
|
380
|
+
this.emit(Events.DEBUG, `Using 2FA Code: ${mfaCode}`);
|
381
|
+
const normal2fa = /(\d{6})/g;
|
382
|
+
const backupCode = /([a-z0-9]{4})-([a-z0-9]{4})/g;
|
383
|
+
if (!mfaCode || typeof mfaCode !== 'string') {
|
384
|
+
throw new Error('LOGIN_FAILED_2FA');
|
385
|
+
}
|
386
|
+
if (normal2fa.test(mfaCode) || backupCode.test(mfaCode)) {
|
387
|
+
const data2 = await this.api.auth.mfa.totp.post({
|
388
|
+
data: {
|
389
|
+
code: mfaCode,
|
390
|
+
ticket: data.ticket,
|
391
|
+
login_source: null,
|
392
|
+
gift_code_sku_id: null,
|
393
|
+
},
|
394
|
+
auth: false,
|
395
|
+
});
|
396
|
+
return this.login(data2.token);
|
397
|
+
} else {
|
398
|
+
throw new Error('LOGIN_FAILED_2FA');
|
399
|
+
}
|
400
|
+
} else if (data.token) {
|
401
|
+
return this.login(data.token);
|
402
|
+
} else {
|
403
|
+
throw new Error('LOGIN_FAILED_UNKNOWN');
|
404
|
+
}
|
405
|
+
}
|
406
|
+
|
407
|
+
/**
|
408
|
+
* Switch the user
|
409
|
+
* @param {string} token User Token
|
410
|
+
* @returns {Promise<string>}
|
411
|
+
*/
|
412
|
+
switchUser(token) {
|
413
|
+
this._clearCache(this.emojis.cache);
|
414
|
+
this._clearCache(this.guilds.cache);
|
415
|
+
this._clearCache(this.channels.cache);
|
416
|
+
this._clearCache(this.users.cache);
|
417
|
+
this._clearCache(this.relationships.cache);
|
418
|
+
this._clearCache(this.sessions.cache);
|
419
|
+
this._clearCache(this.voiceStates.cache);
|
420
|
+
this.ws.status = Status.IDLE;
|
421
|
+
return this.login(token);
|
422
|
+
}
|
423
|
+
|
424
|
+
/**
|
425
|
+
* Sign in with the QR code on your phone.
|
426
|
+
* @param {DiscordAuthWebsocketOptions} options Options
|
427
|
+
* @returns {DiscordAuthWebsocket}
|
428
|
+
* @example
|
429
|
+
* client.QRLogin();
|
430
|
+
*/
|
431
|
+
QRLogin(options = {}) {
|
432
|
+
const QR = new DiscordAuthWebsocket({ ...options, autoLogin: true });
|
433
|
+
this.emit(Events.DEBUG, `Preparing to connect to the gateway (QR Login)`, QR);
|
434
|
+
return QR.connect(this);
|
435
|
+
}
|
436
|
+
|
437
|
+
/**
|
438
|
+
* Implement `remoteAuth`, like using your phone to scan a QR code
|
439
|
+
* @param {string} url URL from QR code
|
440
|
+
* @returns {Promise<void>}
|
441
|
+
*/
|
442
|
+
async remoteAuth(url) {
|
443
|
+
if (!this.isReady()) throw new Error('CLIENT_NOT_READY', 'Remote Auth');
|
444
|
+
// Step 1: Parse URL
|
445
|
+
url = new URL(url);
|
446
|
+
if (
|
447
|
+
!['discordapp.com', 'discord.com'].includes(url.hostname) ||
|
448
|
+
!url.pathname.startsWith('/ra/') ||
|
449
|
+
url.pathname.length <= 4
|
450
|
+
) {
|
451
|
+
throw new Error('INVALID_REMOTE_AUTH_URL');
|
452
|
+
}
|
453
|
+
const hash = url.pathname.replace('/ra/', '');
|
454
|
+
// Step 2: Post > Get handshake_token
|
455
|
+
const res = await this.api.users['@me']['remote-auth'].post({
|
456
|
+
data: {
|
457
|
+
fingerprint: hash,
|
458
|
+
},
|
459
|
+
});
|
460
|
+
const handshake_token = res.handshake_token;
|
461
|
+
// Step 3: Post
|
462
|
+
return this.api.users['@me']['remote-auth'].finish.post({ data: { handshake_token, temporary_token: false } });
|
463
|
+
// Cancel
|
464
|
+
// this.api.users['@me']['remote-auth'].cancel.post({ data: { handshake_token } });
|
465
|
+
}
|
466
|
+
|
467
|
+
/**
|
468
|
+
* Create a new token based on the current token
|
469
|
+
* @returns {Promise<string>} New Discord Token
|
470
|
+
*/
|
471
|
+
createToken() {
|
472
|
+
return new Promise((resolve, reject) => {
|
473
|
+
// Step 1: Create DiscordAuthWebsocket
|
474
|
+
const QR = new DiscordAuthWebsocket({
|
475
|
+
hiddenLog: true,
|
476
|
+
generateQR: false,
|
477
|
+
autoLogin: false,
|
478
|
+
debug: false,
|
479
|
+
failIfError: false,
|
480
|
+
userAgent: this.options.http.headers['User-Agent'],
|
481
|
+
wsProperties: this.options.ws.properties,
|
482
|
+
});
|
483
|
+
// Step 2: Add event
|
484
|
+
QR.once('ready', async (_, url) => {
|
485
|
+
try {
|
486
|
+
await this.remoteAuth(url);
|
487
|
+
} catch (e) {
|
488
|
+
reject(e);
|
489
|
+
}
|
490
|
+
}).once('finish', (user, token) => {
|
491
|
+
resolve(token);
|
492
|
+
});
|
493
|
+
// Step 3: Connect
|
494
|
+
QR.connect();
|
495
|
+
});
|
496
|
+
}
|
497
|
+
|
498
|
+
/**
|
499
|
+
* Emitted whenever clientOptions.checkUpdate = false
|
500
|
+
* @event Client#update
|
501
|
+
* @param {string} oldVersion Current version
|
502
|
+
* @param {string} newVersion Latest version
|
503
|
+
*/
|
504
|
+
|
505
|
+
/**
|
506
|
+
* Check for updates
|
507
|
+
* @returns {Promise<Client>}
|
508
|
+
*/
|
509
|
+
async checkUpdate() {
|
510
|
+
const res_ = await (
|
511
|
+
await fetch(`https://registry.npmjs.com/${encodeURIComponent('discord.js-selfbot-v13')}`)
|
512
|
+
).json();
|
513
|
+
try {
|
514
|
+
const latest_tag = res_['dist-tags'].latest;
|
515
|
+
this.emit('update', Discord.version, latest_tag);
|
516
|
+
this.emit('debug', `${chalk.greenBright('[OK]')} Check Update success`);
|
517
|
+
} catch {
|
518
|
+
this.emit('debug', `${chalk.redBright('[Fail]')} Check Update error`);
|
519
|
+
this.emit('update', Discord.version, false);
|
520
|
+
}
|
521
|
+
return this;
|
522
|
+
}
|
523
|
+
|
524
|
+
/**
|
525
|
+
* Returns whether the client has logged in, indicative of being able to access
|
526
|
+
* properties such as `user` and `application`.
|
527
|
+
* @returns {boolean}
|
528
|
+
*/
|
529
|
+
isReady() {
|
530
|
+
return this.ws.status === Status.READY;
|
531
|
+
}
|
532
|
+
|
533
|
+
/**
|
534
|
+
* Logs out, terminates the connection to Discord, and destroys the client.
|
535
|
+
* @returns {void}
|
536
|
+
*/
|
537
|
+
destroy() {
|
538
|
+
super.destroy();
|
539
|
+
|
540
|
+
for (const fn of this._cleanups) fn();
|
541
|
+
this._cleanups.clear();
|
542
|
+
|
543
|
+
if (this.sweepMessageInterval) clearInterval(this.sweepMessageInterval);
|
544
|
+
|
545
|
+
this.sweepers.destroy();
|
546
|
+
this.ws.destroy();
|
547
|
+
this.token = null;
|
548
|
+
this.password = null;
|
549
|
+
}
|
550
|
+
|
551
|
+
/**
|
552
|
+
* Logs out, terminates the connection to Discord, destroys the client and destroys the token.
|
553
|
+
* @returns {Promise<void>}
|
554
|
+
*/
|
555
|
+
async logout() {
|
556
|
+
await this.api.auth.logout.post({
|
557
|
+
data: {
|
558
|
+
provider: null,
|
559
|
+
voip_provider: null,
|
560
|
+
},
|
561
|
+
});
|
562
|
+
await this.destroy();
|
563
|
+
}
|
564
|
+
|
565
|
+
/**
|
566
|
+
* Options used when fetching an invite from Discord.
|
567
|
+
* @typedef {Object} ClientFetchInviteOptions
|
568
|
+
* @property {Snowflake} [guildScheduledEventId] The id of the guild scheduled event to include with
|
569
|
+
* the invite
|
570
|
+
*/
|
571
|
+
|
572
|
+
/**
|
573
|
+
* Obtains an invite from Discord.
|
574
|
+
* @param {InviteResolvable} invite Invite code or URL
|
575
|
+
* @param {ClientFetchInviteOptions} [options] Options for fetching the invite
|
576
|
+
* @returns {Promise<Invite>}
|
577
|
+
* @example
|
578
|
+
* client.fetchInvite('https://discord.gg/djs')
|
579
|
+
* .then(invite => console.log(`Obtained invite with code: ${invite.code}`))
|
580
|
+
* .catch(console.error);
|
581
|
+
*/
|
582
|
+
async fetchInvite(invite, options) {
|
583
|
+
const code = DataResolver.resolveInviteCode(invite);
|
584
|
+
const data = await this.api.invites(code).get({
|
585
|
+
query: { with_counts: true, with_expiration: true, guild_scheduled_event_id: options?.guildScheduledEventId },
|
586
|
+
});
|
587
|
+
return new Invite(this, data);
|
588
|
+
}
|
589
|
+
|
590
|
+
/**
|
591
|
+
* Join this Guild using this invite (fast)
|
592
|
+
* @param {InviteResolvable} invite Invite code or URL
|
593
|
+
* @returns {Promise<void>}
|
594
|
+
* @example
|
595
|
+
* await client.acceptInvite('https://discord.gg/genshinimpact')
|
596
|
+
*/
|
597
|
+
async acceptInvite(invite) {
|
598
|
+
const code = DataResolver.resolveInviteCode(invite);
|
599
|
+
if (!code) throw new Error('INVITE_RESOLVE_CODE');
|
600
|
+
if (invite instanceof Invite) {
|
601
|
+
await invite.acceptInvite();
|
602
|
+
} else {
|
603
|
+
await this.api.invites(code).post({
|
604
|
+
headers: {
|
605
|
+
'X-Context-Properties': 'eyJsb2NhdGlvbiI6Ik1hcmtkb3duIExpbmsifQ==', // Markdown Link
|
606
|
+
},
|
607
|
+
data: {
|
608
|
+
session_id: this.sessionId,
|
609
|
+
},
|
610
|
+
});
|
611
|
+
}
|
612
|
+
}
|
613
|
+
|
614
|
+
/**
|
615
|
+
* Redeem nitro from code or url.
|
616
|
+
* @param {string} nitro Nitro url or code
|
617
|
+
* @param {TextChannelResolvable} channel Channel that the code was sent in
|
618
|
+
* @param {Snowflake} [paymentSourceId] Payment source id
|
619
|
+
* @returns {Promise<any>}
|
620
|
+
*/
|
621
|
+
redeemNitro(nitro, channel, paymentSourceId) {
|
622
|
+
if (typeof nitro !== 'string') throw new Error('INVALID_NITRO');
|
623
|
+
const nitroCode =
|
624
|
+
nitro.match(/(discord.gift|discord.com|discordapp.com\/gifts)\/(\w{16,25})/) ||
|
625
|
+
nitro.match(/(discord\.gift\/|discord\.com\/gifts\/|discordapp\.com\/gifts\/)(\w+)/);
|
626
|
+
if (!nitroCode) return false;
|
627
|
+
const code = nitroCode[2];
|
628
|
+
channel = this.channels.resolveId(channel);
|
629
|
+
return this.api.entitlements['gift-codes'](code).redeem.post({
|
630
|
+
auth: true,
|
631
|
+
data: { channel_id: channel || null, payment_source_id: paymentSourceId || null },
|
632
|
+
});
|
633
|
+
}
|
634
|
+
|
635
|
+
/**
|
636
|
+
* Obtains a template from Discord.
|
637
|
+
* @param {GuildTemplateResolvable} template Template code or URL
|
638
|
+
* @returns {Promise<GuildTemplate>}
|
639
|
+
* @example
|
640
|
+
* client.fetchGuildTemplate('https://discord.new/FKvmczH2HyUf')
|
641
|
+
* .then(template => console.log(`Obtained template with code: ${template.code}`))
|
642
|
+
* .catch(console.error);
|
643
|
+
*/
|
644
|
+
async fetchGuildTemplate(template) {
|
645
|
+
const code = DataResolver.resolveGuildTemplateCode(template);
|
646
|
+
const data = await this.api.guilds.templates(code).get();
|
647
|
+
return new GuildTemplate(this, data);
|
648
|
+
}
|
649
|
+
|
650
|
+
/**
|
651
|
+
* Obtains a webhook from Discord.
|
652
|
+
* @param {Snowflake} id The webhook's id
|
653
|
+
* @param {string} [token] Token for the webhook
|
654
|
+
* @returns {Promise<Webhook>}
|
655
|
+
* @example
|
656
|
+
* client.fetchWebhook('id', 'token')
|
657
|
+
* .then(webhook => console.log(`Obtained webhook with name: ${webhook.name}`))
|
658
|
+
* .catch(console.error);
|
659
|
+
*/
|
660
|
+
async fetchWebhook(id, token) {
|
661
|
+
const data = await this.api.webhooks(id, token).get();
|
662
|
+
return new Webhook(this, { token, ...data });
|
663
|
+
}
|
664
|
+
|
665
|
+
/**
|
666
|
+
* Obtains the available voice regions from Discord.
|
667
|
+
* @returns {Promise<Collection<string, VoiceRegion>>}
|
668
|
+
* @example
|
669
|
+
* client.fetchVoiceRegions()
|
670
|
+
* .then(regions => console.log(`Available regions are: ${regions.map(region => region.name).join(', ')}`))
|
671
|
+
* .catch(console.error);
|
672
|
+
*/
|
673
|
+
async fetchVoiceRegions() {
|
674
|
+
const apiRegions = await this.api.voice.regions.get();
|
675
|
+
const regions = new Collection();
|
676
|
+
for (const region of apiRegions) regions.set(region.id, new VoiceRegion(region));
|
677
|
+
return regions;
|
678
|
+
}
|
679
|
+
|
680
|
+
/**
|
681
|
+
* Obtains a sticker from Discord.
|
682
|
+
* @param {Snowflake} id The sticker's id
|
683
|
+
* @returns {Promise<Sticker>}
|
684
|
+
* @example
|
685
|
+
* client.fetchSticker('id')
|
686
|
+
* .then(sticker => console.log(`Obtained sticker with name: ${sticker.name}`))
|
687
|
+
* .catch(console.error);
|
688
|
+
*/
|
689
|
+
async fetchSticker(id) {
|
690
|
+
const data = await this.api.stickers(id).get();
|
691
|
+
return new Sticker(this, data);
|
692
|
+
}
|
693
|
+
|
694
|
+
/**
|
695
|
+
* Obtains the list of sticker packs available to Nitro subscribers from Discord.
|
696
|
+
* @returns {Promise<Collection<Snowflake, StickerPack>>}
|
697
|
+
* @example
|
698
|
+
* client.fetchPremiumStickerPacks()
|
699
|
+
* .then(packs => console.log(`Available sticker packs are: ${packs.map(pack => pack.name).join(', ')}`))
|
700
|
+
* .catch(console.error);
|
701
|
+
*/
|
702
|
+
async fetchPremiumStickerPacks() {
|
703
|
+
const data = await this.api('sticker-packs').get();
|
704
|
+
return new Collection(data.sticker_packs.map(p => [p.id, new StickerPack(this, p)]));
|
705
|
+
}
|
706
|
+
/**
|
707
|
+
* A last ditch cleanup function for garbage collection.
|
708
|
+
* @param {Function} options.cleanup The function called to GC
|
709
|
+
* @param {string} [options.message] The message to send after a successful GC
|
710
|
+
* @param {string} [options.name] The name of the item being GCed
|
711
|
+
* @private
|
712
|
+
*/
|
713
|
+
_finalize({ cleanup, message, name }) {
|
714
|
+
try {
|
715
|
+
cleanup();
|
716
|
+
this._cleanups.delete(cleanup);
|
717
|
+
if (message) {
|
718
|
+
this.emit(Events.DEBUG, message);
|
719
|
+
}
|
720
|
+
} catch {
|
721
|
+
this.emit(Events.DEBUG, `Garbage collection failed on ${name ?? 'an unknown item'}.`);
|
722
|
+
}
|
723
|
+
}
|
724
|
+
|
725
|
+
/**
|
726
|
+
* Clear a cache
|
727
|
+
* @param {Collection} cache The cache to clear
|
728
|
+
* @returns {number} The number of removed entries
|
729
|
+
* @private
|
730
|
+
*/
|
731
|
+
_clearCache(cache) {
|
732
|
+
return cache.sweep(() => true);
|
733
|
+
}
|
734
|
+
|
735
|
+
/**
|
736
|
+
* Sweeps all text-based channels' messages and removes the ones older than the max message lifetime.
|
737
|
+
* If the message has been edited, the time of the edit is used rather than the time of the original message.
|
738
|
+
* @param {number} [lifetime=this.options.messageCacheLifetime] Messages that are older than this (in seconds)
|
739
|
+
* will be removed from the caches. The default is based on {@link ClientOptions#messageCacheLifetime}
|
740
|
+
* @returns {number} Amount of messages that were removed from the caches,
|
741
|
+
* or -1 if the message cache lifetime is unlimited
|
742
|
+
* @example
|
743
|
+
* // Remove all messages older than 1800 seconds from the messages cache
|
744
|
+
* const amount = client.sweepMessages(1800);
|
745
|
+
* console.log(`Successfully removed ${amount} messages from the cache.`);
|
746
|
+
*/
|
747
|
+
sweepMessages(lifetime = this.options.messageCacheLifetime) {
|
748
|
+
if (typeof lifetime !== 'number' || isNaN(lifetime)) {
|
749
|
+
throw new TypeError('INVALID_TYPE', 'lifetime', 'number');
|
750
|
+
}
|
751
|
+
if (lifetime <= 0) {
|
752
|
+
this.emit(Events.DEBUG, "Didn't sweep messages - lifetime is unlimited");
|
753
|
+
return -1;
|
754
|
+
}
|
755
|
+
|
756
|
+
const messages = this.sweepers.sweepMessages(Sweepers.outdatedMessageSweepFilter(lifetime)());
|
757
|
+
this.emit(Events.DEBUG, `Swept ${messages} messages older than ${lifetime} seconds`);
|
758
|
+
return messages;
|
759
|
+
}
|
760
|
+
|
761
|
+
/**
|
762
|
+
* Obtains a guild preview from Discord, available for all guilds the bot is in and all Discoverable guilds.
|
763
|
+
* @param {GuildResolvable} guild The guild to fetch the preview for
|
764
|
+
* @returns {Promise<GuildPreview>}
|
765
|
+
*/
|
766
|
+
async fetchGuildPreview(guild) {
|
767
|
+
const id = this.guilds.resolveId(guild);
|
768
|
+
if (!id) throw new TypeError('INVALID_TYPE', 'guild', 'GuildResolvable');
|
769
|
+
const data = await this.api.guilds(id).preview.get();
|
770
|
+
return new GuildPreview(this, data);
|
771
|
+
}
|
772
|
+
|
773
|
+
/**
|
774
|
+
* Obtains the widget data of a guild from Discord, available for guilds with the widget enabled.
|
775
|
+
* @param {GuildResolvable} guild The guild to fetch the widget data for
|
776
|
+
* @returns {Promise<Widget>}
|
777
|
+
*/
|
778
|
+
async fetchGuildWidget(guild) {
|
779
|
+
const id = this.guilds.resolveId(guild);
|
780
|
+
if (!id) throw new TypeError('INVALID_TYPE', 'guild', 'GuildResolvable');
|
781
|
+
const data = await this.api.guilds(id, 'widget.json').get();
|
782
|
+
return new Widget(this, data);
|
783
|
+
}
|
784
|
+
|
785
|
+
/**
|
786
|
+
* Options for {@link Client#generateInvite}.
|
787
|
+
* @typedef {Object} InviteGenerationOptions
|
788
|
+
* @property {InviteScope[]} scopes Scopes that should be requested
|
789
|
+
* @property {PermissionResolvable} [permissions] Permissions to request
|
790
|
+
* @property {GuildResolvable} [guild] Guild to preselect
|
791
|
+
* @property {boolean} [disableGuildSelect] Whether to disable the guild selection
|
792
|
+
*/
|
793
|
+
|
794
|
+
/**
|
795
|
+
* Generates a link that can be used to invite the bot to a guild.
|
796
|
+
* @param {InviteGenerationOptions} [options={}] Options for the invite
|
797
|
+
* @returns {string}
|
798
|
+
* @example
|
799
|
+
* const link = client.generateInvite({
|
800
|
+
* scopes: ['applications.commands'],
|
801
|
+
* });
|
802
|
+
* console.log(`Generated application invite link: ${link}`);
|
803
|
+
* @example
|
804
|
+
* const link = client.generateInvite({
|
805
|
+
* permissions: [
|
806
|
+
* Permissions.FLAGS.SEND_MESSAGES,
|
807
|
+
* Permissions.FLAGS.MANAGE_GUILD,
|
808
|
+
* Permissions.FLAGS.MENTION_EVERYONE,
|
809
|
+
* ],
|
810
|
+
* scopes: ['bot'],
|
811
|
+
* });
|
812
|
+
* console.log(`Generated bot invite link: ${link}`);
|
813
|
+
*/
|
814
|
+
generateInvite(options = {}) {
|
815
|
+
if (typeof options !== 'object') throw new TypeError('INVALID_TYPE', 'options', 'object', true);
|
816
|
+
if (!this.application) throw new Error('CLIENT_NOT_READY', 'generate an invite link');
|
817
|
+
|
818
|
+
const query = new URLSearchParams({
|
819
|
+
client_id: this.application.id,
|
820
|
+
});
|
821
|
+
|
822
|
+
const { scopes } = options;
|
823
|
+
if (typeof scopes === 'undefined') {
|
824
|
+
throw new TypeError('INVITE_MISSING_SCOPES');
|
825
|
+
}
|
826
|
+
if (!Array.isArray(scopes)) {
|
827
|
+
throw new TypeError('INVALID_TYPE', 'scopes', 'Array of Invite Scopes', true);
|
828
|
+
}
|
829
|
+
if (!scopes.some(scope => ['bot', 'applications.commands'].includes(scope))) {
|
830
|
+
throw new TypeError('INVITE_MISSING_SCOPES');
|
831
|
+
}
|
832
|
+
const invalidScope = scopes.find(scope => !InviteScopes.includes(scope));
|
833
|
+
if (invalidScope) {
|
834
|
+
throw new TypeError('INVALID_ELEMENT', 'Array', 'scopes', invalidScope);
|
835
|
+
}
|
836
|
+
query.set('scope', scopes.join(' '));
|
837
|
+
|
838
|
+
if (options.permissions) {
|
839
|
+
const permissions = Permissions.resolve(options.permissions);
|
840
|
+
if (permissions) query.set('permissions', permissions);
|
841
|
+
}
|
842
|
+
|
843
|
+
if (options.disableGuildSelect) {
|
844
|
+
query.set('disable_guild_select', true);
|
845
|
+
}
|
846
|
+
|
847
|
+
if (options.guild) {
|
848
|
+
const guildId = this.guilds.resolveId(options.guild);
|
849
|
+
if (!guildId) throw new TypeError('INVALID_TYPE', 'options.guild', 'GuildResolvable');
|
850
|
+
query.set('guild_id', guildId);
|
851
|
+
}
|
852
|
+
|
853
|
+
return `${this.options.http.api}${this.api.oauth2.authorize}?${query}`;
|
854
|
+
}
|
855
|
+
|
856
|
+
toJSON() {
|
857
|
+
return super.toJSON({
|
858
|
+
readyAt: false,
|
859
|
+
});
|
860
|
+
}
|
861
|
+
|
862
|
+
/**
|
863
|
+
* Calls {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval} on a script
|
864
|
+
* with the client as `this`.
|
865
|
+
* @param {string} script Script to eval
|
866
|
+
* @returns {*}
|
867
|
+
* @private
|
868
|
+
*/
|
869
|
+
_eval(script) {
|
870
|
+
return eval(script);
|
871
|
+
}
|
872
|
+
|
873
|
+
/**
|
874
|
+
* Sets the client's presence. (Sync Setting).
|
875
|
+
* @param {Client} client Discord Client
|
876
|
+
* @private
|
877
|
+
*/
|
878
|
+
customStatusAuto(client) {
|
879
|
+
client = client ?? this;
|
880
|
+
if (!client.user) return;
|
881
|
+
const custom_status = new CustomStatus();
|
882
|
+
if (!client.settings.rawSetting.custom_status?.text && !client.settings.rawSetting.custom_status?.emoji_name) {
|
883
|
+
client.user.setPresence({
|
884
|
+
activities: this.presence.activities.filter(a => a.type !== 'CUSTOM'),
|
885
|
+
status: client.settings.rawSetting.status ?? 'invisible',
|
886
|
+
});
|
887
|
+
} else {
|
888
|
+
custom_status.setEmoji({
|
889
|
+
name: client.settings.rawSetting.custom_status?.emoji_name,
|
890
|
+
id: client.settings.rawSetting.custom_status?.emoji_id,
|
891
|
+
});
|
892
|
+
custom_status.setState(client.settings.rawSetting.custom_status?.text);
|
893
|
+
client.user.setPresence({
|
894
|
+
activities: [custom_status.toJSON(), ...this.presence.activities.filter(a => a.type !== 'CUSTOM')],
|
895
|
+
status: client.settings.rawSetting.status ?? 'invisible',
|
896
|
+
});
|
897
|
+
}
|
898
|
+
}
|
899
|
+
|
900
|
+
/**
|
901
|
+
* @typedef {Object} OAuth2AuthorizeOptions
|
902
|
+
* @property {string} [guild_id] Guild ID
|
903
|
+
* @property {PermissionResolvable} [permissions] Permissions
|
904
|
+
* @property {boolean} [authorize] Whether to authorize or not
|
905
|
+
* @property {string} [code] 2FA Code
|
906
|
+
* @property {string} [webhook_channel_id] Webhook Channel ID
|
907
|
+
*/
|
908
|
+
|
909
|
+
/**
|
910
|
+
* Authorize an application.
|
911
|
+
* @param {string} url Discord Auth URL
|
912
|
+
* @param {OAuth2AuthorizeOptions} options Oauth2 options
|
913
|
+
* @returns {Promise<Object>}
|
914
|
+
* @example
|
915
|
+
* client.authorizeURL(`https://discord.com/api/oauth2/authorize?client_id=botID&permissions=8&scope=applications.commands%20bot`, {
|
916
|
+
guild_id: "guildID",
|
917
|
+
permissions: "62221393", // your permissions
|
918
|
+
authorize: true
|
919
|
+
})
|
920
|
+
*/
|
921
|
+
authorizeURL(url, options = { authorize: true, permissions: '0' }) {
|
922
|
+
const pathnameAPI = /\/api\/(v\d{1,2}\/)?oauth2\/authorize/;
|
923
|
+
const pathnameURL = /\/oauth2\/authorize/;
|
924
|
+
const url_ = new URL(url);
|
925
|
+
if (
|
926
|
+
!['discord.com', 'canary.discord.com', 'ptb.discord.com'].includes(url_.hostname) ||
|
927
|
+
(!pathnameAPI.test(url_.pathname) && !pathnameURL.test(url_.pathname))
|
928
|
+
) {
|
929
|
+
throw new Error('INVALID_URL', url);
|
930
|
+
}
|
931
|
+
const searchParams = Object.fromEntries(url_.searchParams);
|
932
|
+
options.permissions = `${Permissions.resolve(searchParams.permissions || options.permissions) || 0}`;
|
933
|
+
delete searchParams.permissions;
|
934
|
+
return this.api.oauth2.authorize.post({
|
935
|
+
query: searchParams,
|
936
|
+
data: options,
|
937
|
+
});
|
938
|
+
}
|
939
|
+
|
940
|
+
/**
|
941
|
+
* Makes waiting time for Client.
|
942
|
+
* @param {number} miliseconds Sleeping time as milliseconds.
|
943
|
+
* @returns {Promise<void> | null}
|
944
|
+
*/
|
945
|
+
sleep(miliseconds) {
|
946
|
+
return typeof miliseconds === 'number' ? new Promise(r => setTimeout(r, miliseconds).unref()) : null;
|
947
|
+
}
|
948
|
+
|
949
|
+
/**
|
950
|
+
* Validates the client options.
|
951
|
+
* @param {ClientOptions} [options=this.options] Options to validate
|
952
|
+
* @private
|
953
|
+
*/
|
954
|
+
_validateOptions(options = this.options) {
|
955
|
+
if (typeof options.intents === 'undefined') {
|
956
|
+
throw new TypeError('CLIENT_MISSING_INTENTS');
|
957
|
+
} else {
|
958
|
+
options.intents = Intents.resolve(options.intents);
|
959
|
+
}
|
960
|
+
if (options && typeof options.checkUpdate !== 'boolean') {
|
961
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'checkUpdate', 'a boolean');
|
962
|
+
}
|
963
|
+
if (options && typeof options.syncStatus !== 'boolean') {
|
964
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'syncStatus', 'a boolean');
|
965
|
+
}
|
966
|
+
if (options && typeof options.autoRedeemNitro !== 'boolean') {
|
967
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'autoRedeemNitro', 'a boolean');
|
968
|
+
}
|
969
|
+
if (options && options.captchaService && !captchaServices.includes(options.captchaService)) {
|
970
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'captchaService', captchaServices.join(', '));
|
971
|
+
}
|
972
|
+
// Parse captcha key
|
973
|
+
if (options && captchaServices.includes(options.captchaService) && options.captchaService !== 'custom') {
|
974
|
+
if (typeof options.captchaKey !== 'string') {
|
975
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'captchaKey', 'a string');
|
976
|
+
}
|
977
|
+
switch (options.captchaService) {
|
978
|
+
case '2captcha':
|
979
|
+
if (options.captchaKey.length !== 32) {
|
980
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'captchaKey', 'a 32 character string');
|
981
|
+
}
|
982
|
+
break;
|
983
|
+
case 'capmonster':
|
984
|
+
if (options.captchaKey.length !== 32) {
|
985
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'captchaKey', 'a 32 character string');
|
986
|
+
}
|
987
|
+
break;
|
988
|
+
case 'nopecha': {
|
989
|
+
if (options.captchaKey.length !== 16) {
|
990
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'captchaKey', 'a 16 character string');
|
991
|
+
}
|
992
|
+
break;
|
993
|
+
}
|
994
|
+
}
|
995
|
+
}
|
996
|
+
if (typeof options.captchaRetryLimit !== 'number' || isNaN(options.captchaRetryLimit)) {
|
997
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'captchaRetryLimit', 'a number');
|
998
|
+
}
|
999
|
+
if (options && typeof options.captchaSolver !== 'function') {
|
1000
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'captchaSolver', 'a function');
|
1001
|
+
}
|
1002
|
+
if (options && typeof options.captchaWithProxy !== 'boolean') {
|
1003
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'captchaWithProxy', 'a boolean');
|
1004
|
+
}
|
1005
|
+
if (options && typeof options.DMSync !== 'boolean') {
|
1006
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'DMSync', 'a boolean');
|
1007
|
+
}
|
1008
|
+
if (options && typeof options.patchVoice !== 'boolean') {
|
1009
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'patchVoice', 'a boolean');
|
1010
|
+
}
|
1011
|
+
if (options && options.password && typeof options.password !== 'string') {
|
1012
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'password', 'a string');
|
1013
|
+
}
|
1014
|
+
if (options && options.usingNewAttachmentAPI && typeof options.usingNewAttachmentAPI !== 'boolean') {
|
1015
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'usingNewAttachmentAPI', 'a boolean');
|
1016
|
+
}
|
1017
|
+
if (options && options.interactionTimeout && typeof options.interactionTimeout !== 'number') {
|
1018
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'interactionTimeout', 'a number');
|
1019
|
+
}
|
1020
|
+
if (options && typeof options.proxy !== 'string') {
|
1021
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'proxy', 'a string');
|
1022
|
+
} else if (
|
1023
|
+
options &&
|
1024
|
+
options.proxy &&
|
1025
|
+
typeof options.proxy === 'string' &&
|
1026
|
+
testImportModule('proxy-agent') === false
|
1027
|
+
) {
|
1028
|
+
throw new Error('MISSING_MODULE', 'proxy-agent', 'npm install proxy-agent');
|
1029
|
+
}
|
1030
|
+
if (typeof options.shardCount !== 'number' || isNaN(options.shardCount) || options.shardCount < 1) {
|
1031
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'shardCount', 'a number greater than or equal to 1');
|
1032
|
+
}
|
1033
|
+
if (options.shards && !(options.shards === 'auto' || Array.isArray(options.shards))) {
|
1034
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'shards', "'auto', a number or array of numbers");
|
1035
|
+
}
|
1036
|
+
if (options.shards && !options.shards.length) throw new RangeError('CLIENT_INVALID_PROVIDED_SHARDS');
|
1037
|
+
if (typeof options.makeCache !== 'function') {
|
1038
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'makeCache', 'a function');
|
1039
|
+
}
|
1040
|
+
if (typeof options.messageCacheLifetime !== 'number' || isNaN(options.messageCacheLifetime)) {
|
1041
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'The messageCacheLifetime', 'a number');
|
1042
|
+
}
|
1043
|
+
if (typeof options.messageSweepInterval !== 'number' || isNaN(options.messageSweepInterval)) {
|
1044
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'messageSweepInterval', 'a number');
|
1045
|
+
}
|
1046
|
+
if (typeof options.sweepers !== 'object' || options.sweepers === null) {
|
1047
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'sweepers', 'an object');
|
1048
|
+
}
|
1049
|
+
if (typeof options.invalidRequestWarningInterval !== 'number' || isNaN(options.invalidRequestWarningInterval)) {
|
1050
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'invalidRequestWarningInterval', 'a number');
|
1051
|
+
}
|
1052
|
+
if (!Array.isArray(options.partials)) {
|
1053
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'partials', 'an Array');
|
1054
|
+
}
|
1055
|
+
if (typeof options.waitGuildTimeout !== 'number' || isNaN(options.waitGuildTimeout)) {
|
1056
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'waitGuildTimeout', 'a number');
|
1057
|
+
}
|
1058
|
+
if (typeof options.messageCreateEventGuildTimeout !== 'number' || isNaN(options.messageCreateEventGuildTimeout)) {
|
1059
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'messageCreateEventGuildTimeout', 'a number');
|
1060
|
+
}
|
1061
|
+
if (typeof options.restWsBridgeTimeout !== 'number' || isNaN(options.restWsBridgeTimeout)) {
|
1062
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'restWsBridgeTimeout', 'a number');
|
1063
|
+
}
|
1064
|
+
if (typeof options.restRequestTimeout !== 'number' || isNaN(options.restRequestTimeout)) {
|
1065
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'restRequestTimeout', 'a number');
|
1066
|
+
}
|
1067
|
+
if (typeof options.restGlobalRateLimit !== 'number' || isNaN(options.restGlobalRateLimit)) {
|
1068
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'restGlobalRateLimit', 'a number');
|
1069
|
+
}
|
1070
|
+
if (typeof options.restSweepInterval !== 'number' || isNaN(options.restSweepInterval)) {
|
1071
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'restSweepInterval', 'a number');
|
1072
|
+
}
|
1073
|
+
if (typeof options.retryLimit !== 'number' || isNaN(options.retryLimit)) {
|
1074
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'retryLimit', 'a number');
|
1075
|
+
}
|
1076
|
+
if (typeof options.failIfNotExists !== 'boolean') {
|
1077
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'failIfNotExists', 'a boolean');
|
1078
|
+
}
|
1079
|
+
if (!Array.isArray(options.userAgentSuffix)) {
|
1080
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'userAgentSuffix', 'an array of strings');
|
1081
|
+
}
|
1082
|
+
if (
|
1083
|
+
typeof options.rejectOnRateLimit !== 'undefined' &&
|
1084
|
+
!(typeof options.rejectOnRateLimit === 'function' || Array.isArray(options.rejectOnRateLimit))
|
1085
|
+
) {
|
1086
|
+
throw new TypeError('CLIENT_INVALID_OPTION', 'rejectOnRateLimit', 'an array or a function');
|
1087
|
+
}
|
1088
|
+
}
|
1089
|
+
}
|
1090
|
+
|
1091
|
+
module.exports = Client;
|
1092
|
+
|
1093
|
+
/**
|
1094
|
+
* Emitted for general warnings.
|
1095
|
+
* @event Client#warn
|
1096
|
+
* @param {string} info The warning
|
1097
|
+
*/
|
1098
|
+
|
1099
|
+
/**
|
1100
|
+
* @external Collection
|
1101
|
+
* @see {@link https://discord.js.org/docs/packages/collection/stable/Collection:Class}
|
1102
|
+
*/
|