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,772 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const { Buffer } = require('node:buffer');
|
4
|
+
const { setTimeout } = require('node:timers');
|
5
|
+
const { Collection } = require('@discordjs/collection');
|
6
|
+
require('lodash.permutations');
|
7
|
+
const _ = require('lodash');
|
8
|
+
const CachedManager = require('./CachedManager');
|
9
|
+
const { Error, TypeError, RangeError } = require('../errors');
|
10
|
+
const BaseGuildVoiceChannel = require('../structures/BaseGuildVoiceChannel');
|
11
|
+
const { GuildMember } = require('../structures/GuildMember');
|
12
|
+
const { Role } = require('../structures/Role');
|
13
|
+
const { Events, Opcodes } = require('../util/Constants');
|
14
|
+
const { PartialTypes } = require('../util/Constants');
|
15
|
+
const DataResolver = require('../util/DataResolver');
|
16
|
+
const GuildMemberFlags = require('../util/GuildMemberFlags');
|
17
|
+
const SnowflakeUtil = require('../util/SnowflakeUtil');
|
18
|
+
|
19
|
+
/**
|
20
|
+
* Manages API methods for GuildMembers and stores their cache.
|
21
|
+
* @extends {CachedManager}
|
22
|
+
*/
|
23
|
+
class GuildMemberManager extends CachedManager {
|
24
|
+
constructor(guild, iterable) {
|
25
|
+
super(guild.client, GuildMember, iterable);
|
26
|
+
|
27
|
+
/**
|
28
|
+
* The guild this manager belongs to
|
29
|
+
* @type {Guild}
|
30
|
+
*/
|
31
|
+
this.guild = guild;
|
32
|
+
}
|
33
|
+
|
34
|
+
/**
|
35
|
+
* The cache of this Manager
|
36
|
+
* @type {Collection<Snowflake, GuildMember>}
|
37
|
+
* @name GuildMemberManager#cache
|
38
|
+
*/
|
39
|
+
|
40
|
+
_add(data, cache = true) {
|
41
|
+
return super._add(data, cache, { id: data.user.id, extras: [this.guild] });
|
42
|
+
}
|
43
|
+
|
44
|
+
/**
|
45
|
+
* Data that resolves to give a GuildMember object. This can be:
|
46
|
+
* * A GuildMember object
|
47
|
+
* * A User resolvable
|
48
|
+
* @typedef {GuildMember|UserResolvable} GuildMemberResolvable
|
49
|
+
*/
|
50
|
+
|
51
|
+
/**
|
52
|
+
* Resolves a {@link GuildMemberResolvable} to a {@link GuildMember} object.
|
53
|
+
* @param {GuildMemberResolvable} member The user that is part of the guild
|
54
|
+
* @returns {?GuildMember}
|
55
|
+
*/
|
56
|
+
resolve(member) {
|
57
|
+
const memberResolvable = super.resolve(member);
|
58
|
+
if (memberResolvable) return memberResolvable;
|
59
|
+
const userResolvable = this.client.users.resolveId(member);
|
60
|
+
if (userResolvable) return super.resolve(userResolvable);
|
61
|
+
return null;
|
62
|
+
}
|
63
|
+
|
64
|
+
/**
|
65
|
+
* Resolves a {@link GuildMemberResolvable} to a member id.
|
66
|
+
* @param {GuildMemberResolvable} member The user that is part of the guild
|
67
|
+
* @returns {?Snowflake}
|
68
|
+
*/
|
69
|
+
resolveId(member) {
|
70
|
+
const memberResolvable = super.resolveId(member);
|
71
|
+
if (memberResolvable) return memberResolvable;
|
72
|
+
const userResolvable = this.client.users.resolveId(member);
|
73
|
+
return this.cache.has(userResolvable) ? userResolvable : null;
|
74
|
+
}
|
75
|
+
|
76
|
+
/**
|
77
|
+
* Options used to add a user to a guild using OAuth2.
|
78
|
+
* @typedef {Object} AddGuildMemberOptions
|
79
|
+
* @property {string} accessToken An OAuth2 access token for the user with the `guilds.join` scope granted to the
|
80
|
+
* bot's application
|
81
|
+
* @property {string} [nick] The nickname to give to the member (requires `MANAGE_NICKNAMES`)
|
82
|
+
* @property {Collection<Snowflake, Role>|RoleResolvable[]} [roles] The roles to add to the member
|
83
|
+
* (requires `MANAGE_ROLES`)
|
84
|
+
* @property {boolean} [mute] Whether the member should be muted (requires `MUTE_MEMBERS`)
|
85
|
+
* @property {boolean} [deaf] Whether the member should be deafened (requires `DEAFEN_MEMBERS`)
|
86
|
+
* @property {boolean} [force] Whether to skip the cache check and call the API directly
|
87
|
+
* @property {boolean} [fetchWhenExisting=true] Whether to fetch the user if not cached and already a member
|
88
|
+
*/
|
89
|
+
|
90
|
+
/**
|
91
|
+
* Adds a user to the guild using OAuth2. Requires the `CREATE_INSTANT_INVITE` permission.
|
92
|
+
* @param {UserResolvable} user The user to add to the guild
|
93
|
+
* @param {AddGuildMemberOptions} options Options for adding the user to the guild
|
94
|
+
* @returns {Promise<GuildMember|null>}
|
95
|
+
*/
|
96
|
+
async add(user, options) {
|
97
|
+
const userId = this.client.users.resolveId(user);
|
98
|
+
if (!userId) throw new TypeError('INVALID_TYPE', 'user', 'UserResolvable');
|
99
|
+
if (!options.force) {
|
100
|
+
const cachedUser = this.cache.get(userId);
|
101
|
+
if (cachedUser) return cachedUser;
|
102
|
+
}
|
103
|
+
const resolvedOptions = {
|
104
|
+
access_token: options.accessToken,
|
105
|
+
nick: options.nick,
|
106
|
+
mute: options.mute,
|
107
|
+
deaf: options.deaf,
|
108
|
+
};
|
109
|
+
if (options.roles) {
|
110
|
+
if (!Array.isArray(options.roles) && !(options.roles instanceof Collection)) {
|
111
|
+
throw new TypeError('INVALID_TYPE', 'options.roles', 'Array or Collection of Roles or Snowflakes', true);
|
112
|
+
}
|
113
|
+
const resolvedRoles = [];
|
114
|
+
for (const role of options.roles.values()) {
|
115
|
+
const resolvedRole = this.guild.roles.resolveId(role);
|
116
|
+
if (!resolvedRole) throw new TypeError('INVALID_ELEMENT', 'Array or Collection', 'options.roles', role);
|
117
|
+
resolvedRoles.push(resolvedRole);
|
118
|
+
}
|
119
|
+
resolvedOptions.roles = resolvedRoles;
|
120
|
+
}
|
121
|
+
const data = await this.client.api.guilds(this.guild.id).members(userId).put({ data: resolvedOptions });
|
122
|
+
// Data is an empty buffer if the member is already part of the guild.
|
123
|
+
return data instanceof Buffer ? (options.fetchWhenExisting === false ? null : this.fetch(userId)) : this._add(data);
|
124
|
+
}
|
125
|
+
|
126
|
+
/**
|
127
|
+
* The client user as a GuildMember of this guild
|
128
|
+
* @type {?GuildMember}
|
129
|
+
* @readonly
|
130
|
+
*/
|
131
|
+
get me() {
|
132
|
+
return (
|
133
|
+
this.resolve(this.client.user.id) ??
|
134
|
+
(this.client.options.partials.includes(PartialTypes.GUILD_MEMBER)
|
135
|
+
? this._add({ user: { id: this.client.user.id } }, true)
|
136
|
+
: null)
|
137
|
+
);
|
138
|
+
}
|
139
|
+
|
140
|
+
/**
|
141
|
+
* Options used to fetch a single member from a guild.
|
142
|
+
* @typedef {BaseFetchOptions} FetchMemberOptions
|
143
|
+
* @property {UserResolvable} user The user to fetch
|
144
|
+
*/
|
145
|
+
|
146
|
+
/**
|
147
|
+
* Options used to fetch multiple members from a guild.
|
148
|
+
* @typedef {Object} FetchMembersOptions
|
149
|
+
* @property {UserResolvable|UserResolvable[]} user The user(s) to fetch
|
150
|
+
* @property {?string} query Limit fetch to members with similar usernames
|
151
|
+
* @property {number} [limit=0] Maximum number of members to request
|
152
|
+
* @property {boolean} [withPresences=false] Whether or not to include the presences
|
153
|
+
* @property {number} [time=120e3] Timeout for receipt of members
|
154
|
+
* @property {?string} nonce Nonce for this request (32 characters max - default to base 16 now timestamp)
|
155
|
+
* @property {boolean} [force=false] Whether to skip the cache check and request the API
|
156
|
+
*/
|
157
|
+
|
158
|
+
/**
|
159
|
+
* Fetches member(s) from Discord, even if they're offline.
|
160
|
+
* @param {UserResolvable|FetchMemberOptions|FetchMembersOptions} [options] If a UserResolvable, the user to fetch.
|
161
|
+
* If undefined, fetches all members.
|
162
|
+
* If a query, it limits the results to users with similar usernames.
|
163
|
+
* @returns {Promise<GuildMember|Collection<Snowflake, GuildMember>>}
|
164
|
+
* @example
|
165
|
+
* // Fetch all members from a guild
|
166
|
+
* guild.members.fetch()
|
167
|
+
* .then(console.log)
|
168
|
+
* .catch(console.error);
|
169
|
+
* @example
|
170
|
+
* // Fetch a single member
|
171
|
+
* guild.members.fetch('66564597481480192')
|
172
|
+
* .then(console.log)
|
173
|
+
* .catch(console.error);
|
174
|
+
* @example
|
175
|
+
* // Fetch a single member without checking cache
|
176
|
+
* guild.members.fetch({ user, force: true })
|
177
|
+
* .then(console.log)
|
178
|
+
* .catch(console.error)
|
179
|
+
* @example
|
180
|
+
* // Fetch a single member without caching
|
181
|
+
* guild.members.fetch({ user, cache: false })
|
182
|
+
* .then(console.log)
|
183
|
+
* .catch(console.error);
|
184
|
+
* @example
|
185
|
+
* // Fetch by an array of users including their presences
|
186
|
+
* guild.members.fetch({ user: ['66564597481480192', '191615925336670208'], withPresences: true })
|
187
|
+
* .then(console.log)
|
188
|
+
* .catch(console.error);
|
189
|
+
* @example
|
190
|
+
* // Fetch by query
|
191
|
+
* guild.members.fetch({ query: 'hydra', limit: 1 })
|
192
|
+
* .then(console.log)
|
193
|
+
* .catch(console.error);
|
194
|
+
* @see {@link https://github.com/aiko-chan-ai/discord.js-selfbot-v13/blob/main/Document/FetchGuildMember.md}
|
195
|
+
*/
|
196
|
+
fetch(options) {
|
197
|
+
if (!options || (typeof options === 'object' && !('user' in options) && !('query' in options))) {
|
198
|
+
if (
|
199
|
+
this.guild.members.me.permissions.has('KICK_MEMBERS') ||
|
200
|
+
this.guild.members.me.permissions.has('BAN_MEMBERS') ||
|
201
|
+
this.guild.members.me.permissions.has('MANAGE_ROLES')
|
202
|
+
) {
|
203
|
+
return this._fetchMany();
|
204
|
+
} else if (this.guild.memberCount <= 10000) {
|
205
|
+
return this.fetchByMemberSafety();
|
206
|
+
} else {
|
207
|
+
// NOTE: This is a very slow method, and can take up to 999+ minutes to complete.
|
208
|
+
return this.fetchBruteforce({
|
209
|
+
delay: 50,
|
210
|
+
skipWarn: true,
|
211
|
+
depth: 1,
|
212
|
+
});
|
213
|
+
}
|
214
|
+
}
|
215
|
+
const user = this.client.users.resolveId(options);
|
216
|
+
if (user) return this._fetchSingle({ user, cache: true });
|
217
|
+
if (options.user) {
|
218
|
+
if (Array.isArray(options.user)) {
|
219
|
+
options.user = options.user.map(u => this.client.users.resolveId(u));
|
220
|
+
return this._fetchMany(options);
|
221
|
+
} else {
|
222
|
+
options.user = this.client.users.resolveId(options.user);
|
223
|
+
}
|
224
|
+
if (!options.limit && !options.withPresences) return this._fetchSingle(options);
|
225
|
+
}
|
226
|
+
return this._fetchMany(options);
|
227
|
+
}
|
228
|
+
|
229
|
+
/**
|
230
|
+
* Fetches the client user as a GuildMember of the guild.
|
231
|
+
* @param {BaseFetchOptions} [options] The options for fetching the member
|
232
|
+
* @returns {Promise<GuildMember>}
|
233
|
+
*/
|
234
|
+
fetchMe(options) {
|
235
|
+
return this.fetch({ ...options, user: this.client.user.id });
|
236
|
+
}
|
237
|
+
|
238
|
+
/**
|
239
|
+
* Options used for searching guild members.
|
240
|
+
* @typedef {Object} GuildSearchMembersOptions
|
241
|
+
* @property {string} query Filter members whose username or nickname start with this query
|
242
|
+
* @property {number} [limit=1] Maximum number of members to search
|
243
|
+
* @property {boolean} [cache=true] Whether or not to cache the fetched member(s)
|
244
|
+
*/
|
245
|
+
|
246
|
+
/**
|
247
|
+
* Searches for members in the guild based on a query.
|
248
|
+
* @param {GuildSearchMembersOptions} options Options for searching members
|
249
|
+
* @returns {Promise<Collection<Snowflake, GuildMember>>}
|
250
|
+
*/
|
251
|
+
async search({ query, limit = 1, cache = true } = {}) {
|
252
|
+
const data = await this.client.api.guilds(this.guild.id).members.search.get({ query: { query, limit } });
|
253
|
+
return data.reduce((col, member) => col.set(member.user.id, this._add(member, cache)), new Collection());
|
254
|
+
}
|
255
|
+
|
256
|
+
/**
|
257
|
+
* Options used for listing guild members.
|
258
|
+
* @typedef {Object} GuildListMembersOptions
|
259
|
+
* @property {Snowflake} [after] Limit fetching members to those with an id greater than the supplied id
|
260
|
+
* @property {number} [limit=1] Maximum number of members to list
|
261
|
+
* @property {boolean} [cache=true] Whether or not to cache the fetched member(s)
|
262
|
+
*/
|
263
|
+
|
264
|
+
/**
|
265
|
+
* Lists up to 1000 members of the guild.
|
266
|
+
* @param {GuildListMembersOptions} [options] Options for listing members
|
267
|
+
* @returns {Promise<Collection<Snowflake, GuildMember>>}
|
268
|
+
*/
|
269
|
+
async list({ after, limit = 1, cache = true } = {}) {
|
270
|
+
const data = await this.client.api.guilds(this.guild.id).members.get({ query: { after, limit } });
|
271
|
+
return data.reduce((col, member) => col.set(member.user.id, this._add(member, cache)), new Collection());
|
272
|
+
}
|
273
|
+
|
274
|
+
/**
|
275
|
+
* The data for editing a guild member.
|
276
|
+
* @typedef {Object} GuildMemberEditData
|
277
|
+
* @property {?string} [nick] The nickname to set for the member
|
278
|
+
* @property {Collection<Snowflake, Role>|RoleResolvable[]} [roles] The roles or role ids to apply
|
279
|
+
* @property {boolean} [mute] Whether or not the member should be muted
|
280
|
+
* @property {boolean} [deaf] Whether or not the member should be deafened
|
281
|
+
* @property {GuildVoiceChannelResolvable|null} [channel] Channel to move the member to
|
282
|
+
* (if they are connected to voice), or `null` if you want to disconnect them from voice
|
283
|
+
* @property {DateResolvable|null} [communicationDisabledUntil] The date or timestamp
|
284
|
+
* for the member's communication to be disabled until. Provide `null` to enable communication again.
|
285
|
+
* @property {GuildMemberFlagsResolvable} [flags] The flags to set for the member
|
286
|
+
* @property {?(BufferResolvable|Base64Resolvable)} [avatar] The new guild avatar
|
287
|
+
* @property {?(BufferResolvable|Base64Resolvable)} [banner] The new guild banner
|
288
|
+
* @property {?string} [bio] The new guild about me
|
289
|
+
*/
|
290
|
+
|
291
|
+
/**
|
292
|
+
* Edits a member of the guild.
|
293
|
+
* <info>The user must be a member of the guild</info>
|
294
|
+
* @param {UserResolvable} user The member to edit
|
295
|
+
* @param {GuildMemberEditData} data The data to edit the member with
|
296
|
+
* @param {string} [reason] Reason for editing this user
|
297
|
+
* @returns {Promise<GuildMember>}
|
298
|
+
*/
|
299
|
+
async edit(user, data, reason) {
|
300
|
+
const id = this.client.users.resolveId(user);
|
301
|
+
if (!id) throw new TypeError('INVALID_TYPE', 'user', 'UserResolvable');
|
302
|
+
|
303
|
+
// Clone the data object for immutability
|
304
|
+
const _data = { ...data };
|
305
|
+
if (_data.channel) {
|
306
|
+
_data.channel = this.guild.channels.resolve(_data.channel);
|
307
|
+
if (!(_data.channel instanceof BaseGuildVoiceChannel)) {
|
308
|
+
throw new Error('GUILD_VOICE_CHANNEL_RESOLVE');
|
309
|
+
}
|
310
|
+
_data.channel_id = _data.channel.id;
|
311
|
+
_data.channel = undefined;
|
312
|
+
} else if (_data.channel === null) {
|
313
|
+
_data.channel_id = null;
|
314
|
+
_data.channel = undefined;
|
315
|
+
}
|
316
|
+
_data.roles &&= _data.roles.map(role => (role instanceof Role ? role.id : role));
|
317
|
+
|
318
|
+
_data.communication_disabled_until =
|
319
|
+
_data.communicationDisabledUntil && new Date(_data.communicationDisabledUntil).toISOString();
|
320
|
+
|
321
|
+
_data.flags = _data.flags && GuildMemberFlags.resolve(_data.flags);
|
322
|
+
|
323
|
+
// Avatar, banner, bio
|
324
|
+
if (typeof _data.avatar !== 'undefined') {
|
325
|
+
_data.avatar = await DataResolver.resolveImage(_data.avatar);
|
326
|
+
}
|
327
|
+
if (typeof _data.banner !== 'undefined') {
|
328
|
+
_data.banner = await DataResolver.resolveImage(_data.banner);
|
329
|
+
}
|
330
|
+
|
331
|
+
let endpoint = this.client.api.guilds(this.guild.id);
|
332
|
+
if (id === this.client.user.id) {
|
333
|
+
const keys = Object.keys(data);
|
334
|
+
if (keys.length === 1 && ['nick', 'avatar', 'banner', 'bio'].includes(keys[0])) {
|
335
|
+
endpoint = endpoint.members('@me');
|
336
|
+
} else {
|
337
|
+
endpoint = endpoint.members(id);
|
338
|
+
}
|
339
|
+
} else {
|
340
|
+
endpoint = endpoint.members(id);
|
341
|
+
}
|
342
|
+
const d = await endpoint.patch({ data: _data, reason });
|
343
|
+
|
344
|
+
const clone = this.cache.get(id)?._clone();
|
345
|
+
clone?._patch(d);
|
346
|
+
return clone ?? this._add(d, false);
|
347
|
+
}
|
348
|
+
|
349
|
+
/**
|
350
|
+
* Options used for pruning guild members.
|
351
|
+
* <info>It's recommended to set {@link GuildPruneMembersOptions#count options.count}
|
352
|
+
* to `false` for large guilds.</info>
|
353
|
+
* @typedef {Object} GuildPruneMembersOptions
|
354
|
+
* @property {number} [days=7] Number of days of inactivity required to kick
|
355
|
+
* @property {boolean} [dry=false] Get the number of users that will be kicked, without actually kicking them
|
356
|
+
* @property {boolean} [count=true] Whether or not to return the number of users that have been kicked.
|
357
|
+
* @property {RoleResolvable[]} [roles] Array of roles to bypass the "...and no roles" constraint when pruning
|
358
|
+
* @property {string} [reason] Reason for this prune
|
359
|
+
*/
|
360
|
+
|
361
|
+
/**
|
362
|
+
* Prunes members from the guild based on how long they have been inactive.
|
363
|
+
* @param {GuildPruneMembersOptions} [options] Options for pruning
|
364
|
+
* @returns {Promise<number|null>} The number of members that were/will be kicked
|
365
|
+
* @example
|
366
|
+
* // See how many members will be pruned
|
367
|
+
* guild.members.prune({ dry: true })
|
368
|
+
* .then(pruned => console.log(`This will prune ${pruned} people!`))
|
369
|
+
* .catch(console.error);
|
370
|
+
* @example
|
371
|
+
* // Actually prune the members
|
372
|
+
* guild.members.prune({ days: 1, reason: 'too many people!' })
|
373
|
+
* .then(pruned => console.log(`I just pruned ${pruned} people!`))
|
374
|
+
* .catch(console.error);
|
375
|
+
* @example
|
376
|
+
* // Include members with a specified role
|
377
|
+
* guild.members.prune({ days: 7, roles: ['657259391652855808'] })
|
378
|
+
* .then(pruned => console.log(`I just pruned ${pruned} people!`))
|
379
|
+
* .catch(console.error);
|
380
|
+
*/
|
381
|
+
async prune({ days = 7, dry = false, count: compute_prune_count = true, roles = [], reason } = {}) {
|
382
|
+
if (typeof days !== 'number') throw new TypeError('PRUNE_DAYS_TYPE');
|
383
|
+
|
384
|
+
const query = { days };
|
385
|
+
const resolvedRoles = [];
|
386
|
+
|
387
|
+
for (const role of roles) {
|
388
|
+
const resolvedRole = this.guild.roles.resolveId(role);
|
389
|
+
if (!resolvedRole) {
|
390
|
+
throw new TypeError('INVALID_ELEMENT', 'Array', 'options.roles', role);
|
391
|
+
}
|
392
|
+
resolvedRoles.push(resolvedRole);
|
393
|
+
}
|
394
|
+
|
395
|
+
if (resolvedRoles.length) {
|
396
|
+
query.include_roles = dry ? resolvedRoles.join(',') : resolvedRoles;
|
397
|
+
}
|
398
|
+
|
399
|
+
const endpoint = this.client.api.guilds(this.guild.id).prune;
|
400
|
+
|
401
|
+
const { pruned } = await (dry
|
402
|
+
? endpoint.get({ query, reason })
|
403
|
+
: endpoint.post({ data: { ...query, compute_prune_count }, reason }));
|
404
|
+
|
405
|
+
return pruned;
|
406
|
+
}
|
407
|
+
|
408
|
+
/**
|
409
|
+
* Kicks a user from the guild.
|
410
|
+
* <info>The user must be a member of the guild</info>
|
411
|
+
* @param {UserResolvable} user The member to kick
|
412
|
+
* @param {string} [reason] Reason for kicking
|
413
|
+
* @returns {Promise<GuildMember|User|Snowflake>} Result object will be resolved as specifically as possible.
|
414
|
+
* If the GuildMember cannot be resolved, the User will instead be attempted to be resolved. If that also cannot
|
415
|
+
* be resolved, the user's id will be the result.
|
416
|
+
* @example
|
417
|
+
* // Kick a user by id (or with a user/guild member object)
|
418
|
+
* guild.members.kick('84484653687267328')
|
419
|
+
* .then(kickInfo => console.log(`Kicked ${kickInfo.user?.tag ?? kickInfo.tag ?? kickInfo}`))
|
420
|
+
* .catch(console.error);
|
421
|
+
*/
|
422
|
+
async kick(user, reason) {
|
423
|
+
const id = this.client.users.resolveId(user);
|
424
|
+
if (!id) return Promise.reject(new TypeError('INVALID_TYPE', 'user', 'UserResolvable'));
|
425
|
+
|
426
|
+
await this.client.api.guilds(this.guild.id).members(id).delete({ reason });
|
427
|
+
|
428
|
+
return this.resolve(user) ?? this.client.users.resolve(user) ?? id;
|
429
|
+
}
|
430
|
+
|
431
|
+
/**
|
432
|
+
* Bans a user from the guild.
|
433
|
+
* @param {UserResolvable} user The user to ban
|
434
|
+
* @param {BanOptions} [options] Options for the ban
|
435
|
+
* @returns {Promise<GuildMember|User|Snowflake>} Result object will be resolved as specifically as possible.
|
436
|
+
* If the GuildMember cannot be resolved, the User will instead be attempted to be resolved. If that also cannot
|
437
|
+
* be resolved, the user id will be the result.
|
438
|
+
* Internally calls the GuildBanManager#create method.
|
439
|
+
* @example
|
440
|
+
* // Ban a user by id (or with a user/guild member object)
|
441
|
+
* guild.members.ban('84484653687267328')
|
442
|
+
* .then(banInfo => console.log(`Banned ${banInfo.user?.tag ?? banInfo.tag ?? banInfo}`))
|
443
|
+
* .catch(console.error);
|
444
|
+
*/
|
445
|
+
ban(user, options) {
|
446
|
+
return this.guild.bans.create(user, options);
|
447
|
+
}
|
448
|
+
|
449
|
+
/**
|
450
|
+
* Unbans a user from the guild. Internally calls the {@link GuildBanManager#remove} method.
|
451
|
+
* @param {UserResolvable} user The user to unban
|
452
|
+
* @param {string} [reason] Reason for unbanning user
|
453
|
+
* @returns {Promise<?User>} The user that was unbanned
|
454
|
+
* @example
|
455
|
+
* // Unban a user by id (or with a user/guild member object)
|
456
|
+
* guild.members.unban('84484653687267328')
|
457
|
+
* .then(user => console.log(`Unbanned ${user.username} from ${guild.name}`))
|
458
|
+
* .catch(console.error);
|
459
|
+
*/
|
460
|
+
unban(user, reason) {
|
461
|
+
return this.guild.bans.remove(user, reason);
|
462
|
+
}
|
463
|
+
|
464
|
+
async _fetchSingle({ user, cache, force = false }) {
|
465
|
+
if (!force) {
|
466
|
+
const existing = this.cache.get(user);
|
467
|
+
if (existing && !existing.partial) return existing;
|
468
|
+
}
|
469
|
+
|
470
|
+
const data = await this.client.api.guilds(this.guild.id).members(user).get();
|
471
|
+
return this._add(data, cache);
|
472
|
+
}
|
473
|
+
|
474
|
+
/**
|
475
|
+
* Options used to fetch multiple members from a guild.
|
476
|
+
* @typedef {Object} BruteforceOptions
|
477
|
+
* @property {number} [limit=100] Maximum number of members per request
|
478
|
+
* @property {number} [delay=500] Timeout for new requests in ms
|
479
|
+
* @property {number} [depth=1] Permutations length
|
480
|
+
*/
|
481
|
+
|
482
|
+
/**
|
483
|
+
* Fetches multiple members from the guild.
|
484
|
+
* @param {BruteforceOptions} options Options for the bruteforce
|
485
|
+
* @returns {Collection<Snowflake, GuildMember>} (All) members in the guild
|
486
|
+
* @see https://github.com/aiko-chan-ai/discord.js-selfbot-v13/blob/main/Document/FetchGuildMember.md
|
487
|
+
* @example
|
488
|
+
* guild.members.fetchBruteforce()
|
489
|
+
* .then(members => console.log(`Fetched ${members.size} members`))
|
490
|
+
* .catch(console.error);
|
491
|
+
*/
|
492
|
+
fetchBruteforce(options = {}) {
|
493
|
+
const defaultQuery = 'abcdefghijklmnopqrstuvwxyz0123456789!"#$%&\'()*+,-./:;<=>?@[]^_`{|}~ ';
|
494
|
+
let dictionary;
|
495
|
+
let limit = 100;
|
496
|
+
let delay = 500;
|
497
|
+
let depth = 1;
|
498
|
+
if (options?.limit) limit = options?.limit;
|
499
|
+
if (options?.delay) delay = options?.delay;
|
500
|
+
if (options?.depth) depth = options?.depth;
|
501
|
+
if (typeof limit !== 'number') throw new TypeError('INVALID_TYPE', 'limit', 'Number');
|
502
|
+
if (limit < 1 || limit > 100) throw new RangeError('INVALID_RANGE_QUERY_MEMBER');
|
503
|
+
if (typeof delay !== 'number') throw new TypeError('INVALID_TYPE', 'delay', 'Number');
|
504
|
+
if (typeof depth !== 'number') throw new TypeError('INVALID_TYPE', 'depth', 'Number');
|
505
|
+
if (depth < 1) throw new RangeError('INVALID_RANGE_QUERY_MEMBER');
|
506
|
+
if (depth > 2) {
|
507
|
+
console.warn(`[WARNING] GuildMemberManager#fetchBruteforce: depth greater than 2, can lead to very slow speeds`);
|
508
|
+
}
|
509
|
+
if (delay < 500 && !options?.skipWarn) {
|
510
|
+
console.warn(
|
511
|
+
`[WARNING] GuildMemberManager#fetchBruteforce: delay is less than 500ms, this may cause rate limits.`,
|
512
|
+
);
|
513
|
+
}
|
514
|
+
let skipValues = [];
|
515
|
+
// eslint-disable-next-line no-async-promise-executor
|
516
|
+
return new Promise(async (resolve, reject) => {
|
517
|
+
for (let i = 1; i <= depth; i++) {
|
518
|
+
dictionary = _(defaultQuery)
|
519
|
+
.permutations(i)
|
520
|
+
.map(v => _.join(v, ''))
|
521
|
+
.value();
|
522
|
+
for (const query of dictionary) {
|
523
|
+
if (this.guild.members.cache.size >= this.guild.memberCount) break;
|
524
|
+
this.client.emit(
|
525
|
+
'debug',
|
526
|
+
`[INFO] GuildMemberManager#fetchBruteforce: Querying ${query}, Skip: [${skipValues.join(', ')}]`,
|
527
|
+
);
|
528
|
+
if (skipValues.some(v => query.startsWith(v))) continue;
|
529
|
+
await this._fetchMany({ query, limit })
|
530
|
+
.then(members => {
|
531
|
+
if (members.size === 0) skipValues.push(query);
|
532
|
+
})
|
533
|
+
.catch(reject);
|
534
|
+
await this.guild.client.sleep(delay);
|
535
|
+
}
|
536
|
+
}
|
537
|
+
resolve(this.guild.members.cache);
|
538
|
+
});
|
539
|
+
}
|
540
|
+
|
541
|
+
/**
|
542
|
+
* Experimental method to fetch members from the guild.
|
543
|
+
* <info>Lists up to 10000 members of the guild.</info>
|
544
|
+
* @param {number} [timeout=15_000] Timeout for receipt of members in ms
|
545
|
+
* @returns {Promise<Collection<Snowflake, GuildMember>>}
|
546
|
+
*/
|
547
|
+
fetchByMemberSafety(timeout = 15_000) {
|
548
|
+
return new Promise(resolve => {
|
549
|
+
const nonce = SnowflakeUtil.generate();
|
550
|
+
let timeout_ = setTimeout(() => {
|
551
|
+
this.client.removeListener(Events.GUILD_MEMBER_LIST_UPDATE, handler);
|
552
|
+
resolve(this.guild.members.cache);
|
553
|
+
}, timeout).unref();
|
554
|
+
const handler = (members, guild, raw) => {
|
555
|
+
if (guild.id == this.guild.id && raw.nonce == nonce) {
|
556
|
+
if (members.size > 0) {
|
557
|
+
this.client.ws.broadcast({
|
558
|
+
op: 35,
|
559
|
+
d: {
|
560
|
+
guild_id: this.guild.id,
|
561
|
+
query: '',
|
562
|
+
continuation_token: members.first()?.id,
|
563
|
+
nonce,
|
564
|
+
},
|
565
|
+
});
|
566
|
+
} else {
|
567
|
+
clearTimeout(timeout_);
|
568
|
+
this.client.removeListener(Events.GUILD_MEMBER_LIST_UPDATE, handler);
|
569
|
+
resolve(this.guild.members.cache);
|
570
|
+
}
|
571
|
+
}
|
572
|
+
};
|
573
|
+
this.client.on('guildMembersChunk', handler);
|
574
|
+
this.client.ws.broadcast({
|
575
|
+
op: 35,
|
576
|
+
d: {
|
577
|
+
guild_id: this.guild.id,
|
578
|
+
query: '',
|
579
|
+
continuation_token: null,
|
580
|
+
nonce,
|
581
|
+
},
|
582
|
+
});
|
583
|
+
});
|
584
|
+
}
|
585
|
+
|
586
|
+
/**
|
587
|
+
* Fetches multiple members from the guild in the channel.
|
588
|
+
* @param {GuildTextChannelResolvable} channel The channel to get members from (Members has VIEW_CHANNEL permission)
|
589
|
+
* @param {number} [offset=0] Start index of the members to get
|
590
|
+
* @param {boolean} [double=false] Whether to use double range
|
591
|
+
* @param {number} [retryMax=3] Number of retries
|
592
|
+
* @param {number} [time=10e3] Timeout for receipt of members
|
593
|
+
* @returns {Collection<Snowflake, GuildMember>} Members in the guild
|
594
|
+
* @see {@link https://github.com/aiko-chan-ai/discord.js-selfbot-v13/blob/main/Document/FetchGuildMember.md}
|
595
|
+
* @example
|
596
|
+
* const guild = client.guilds.cache.get('id');
|
597
|
+
* const channel = guild.channels.cache.get('id');
|
598
|
+
* // Overlap (slow)
|
599
|
+
* for (let index = 0; index <= guild.memberCount; index += 100) {
|
600
|
+
* await guild.members.fetchMemberList(channel, index, index !== 100).catch(() => {});
|
601
|
+
* await client.sleep(500);
|
602
|
+
* }
|
603
|
+
* // Non-overlap (fast)
|
604
|
+
* for (let index = 0; index <= guild.memberCount; index += 200) {
|
605
|
+
* await guild.members.fetchMemberList(channel, index == 0 ? 100 : index, index !== 100).catch(() => {});
|
606
|
+
* await client.sleep(500);
|
607
|
+
* }
|
608
|
+
* console.log(guild.members.cache.size); // will print the number of members in the guild
|
609
|
+
*/
|
610
|
+
fetchMemberList(channel, offset = 0, double = false, retryMax = 3, time = 10_000) {
|
611
|
+
const channel_ = this.guild.channels.resolve(channel);
|
612
|
+
if (!channel_?.isText()) throw new TypeError('INVALID_TYPE', 'channel', 'GuildTextChannelResolvable');
|
613
|
+
if (typeof offset !== 'number') throw new TypeError('INVALID_TYPE', 'offset', 'Number');
|
614
|
+
if (typeof time !== 'number') throw new TypeError('INVALID_TYPE', 'time', 'Number');
|
615
|
+
if (typeof retryMax !== 'number') throw new TypeError('INVALID_TYPE', 'retryMax', 'Number');
|
616
|
+
if (retryMax < 1) throw new RangeError('INVALID_RANGE_RETRY');
|
617
|
+
if (typeof double !== 'boolean') throw new TypeError('INVALID_TYPE', 'double', 'Boolean');
|
618
|
+
// TODO: if (this.guild.large) throw new Error('GUILD_IS_LARGE');
|
619
|
+
return new Promise((resolve, reject) => {
|
620
|
+
const default_ = [[0, 99]];
|
621
|
+
const fetchedMembers = new Collection();
|
622
|
+
if (offset > 99) {
|
623
|
+
// eslint-disable-next-line no-unused-expressions
|
624
|
+
double
|
625
|
+
? default_.push([offset, offset + 99], [offset + 100, offset + 199])
|
626
|
+
: default_.push([offset, offset + 99]);
|
627
|
+
}
|
628
|
+
let retry = 0;
|
629
|
+
const handler = (members, guild, type, raw) => {
|
630
|
+
timeout.refresh();
|
631
|
+
if (guild.id !== this.guild.id) return;
|
632
|
+
if (type == 'INVALIDATE' && offset > 100) {
|
633
|
+
if (retry < retryMax) {
|
634
|
+
this.guild.shard.send({
|
635
|
+
op: Opcodes.GUILD_SUBSCRIPTIONS,
|
636
|
+
d: {
|
637
|
+
guild_id: this.guild.id,
|
638
|
+
typing: true,
|
639
|
+
threads: true,
|
640
|
+
activities: true,
|
641
|
+
channels: {
|
642
|
+
[channel_.id]: default_,
|
643
|
+
},
|
644
|
+
thread_member_lists: [],
|
645
|
+
members: [],
|
646
|
+
},
|
647
|
+
});
|
648
|
+
retry++;
|
649
|
+
} else {
|
650
|
+
clearTimeout(timeout);
|
651
|
+
this.client.removeListener(Events.GUILD_MEMBER_LIST_UPDATE, handler);
|
652
|
+
this.client.decrementMaxListeners();
|
653
|
+
reject(new Error('INVALIDATE_MEMBER', raw.ops[0].range));
|
654
|
+
}
|
655
|
+
} else {
|
656
|
+
for (const member of members.values()) {
|
657
|
+
fetchedMembers.set(member.id, member);
|
658
|
+
}
|
659
|
+
clearTimeout(timeout);
|
660
|
+
this.client.removeListener(Events.GUILD_MEMBER_LIST_UPDATE, handler);
|
661
|
+
this.client.decrementMaxListeners();
|
662
|
+
resolve(fetchedMembers);
|
663
|
+
}
|
664
|
+
};
|
665
|
+
const timeout = setTimeout(() => {
|
666
|
+
this.client.removeListener(Events.GUILD_MEMBER_LIST_UPDATE, handler);
|
667
|
+
this.client.decrementMaxListeners();
|
668
|
+
reject(new Error('GUILD_MEMBERS_TIMEOUT'));
|
669
|
+
}, time).unref();
|
670
|
+
this.client.incrementMaxListeners();
|
671
|
+
this.client.on(Events.GUILD_MEMBER_LIST_UPDATE, handler);
|
672
|
+
this.guild.shard.send({
|
673
|
+
op: Opcodes.GUILD_SUBSCRIPTIONS,
|
674
|
+
d: {
|
675
|
+
guild_id: this.guild.id,
|
676
|
+
typing: true,
|
677
|
+
threads: true,
|
678
|
+
activities: true,
|
679
|
+
channels: {
|
680
|
+
[channel_.id]: default_,
|
681
|
+
},
|
682
|
+
thread_member_lists: [],
|
683
|
+
members: [],
|
684
|
+
},
|
685
|
+
});
|
686
|
+
});
|
687
|
+
}
|
688
|
+
|
689
|
+
/**
|
690
|
+
* Adds a role to a member.
|
691
|
+
* @param {GuildMemberResolvable} user The user to add the role from
|
692
|
+
* @param {RoleResolvable} role The role to add
|
693
|
+
* @param {string} [reason] Reason for adding the role
|
694
|
+
* @returns {Promise<GuildMember|User|Snowflake>}
|
695
|
+
*/
|
696
|
+
async addRole(user, role, reason) {
|
697
|
+
const userId = this.guild.members.resolveId(user);
|
698
|
+
const roleId = this.guild.roles.resolveId(role);
|
699
|
+
|
700
|
+
await this.client.api.guilds(this.guild.id).members(userId).roles(roleId).put({ reason });
|
701
|
+
|
702
|
+
return this.resolve(user) ?? this.client.users.resolve(user) ?? userId;
|
703
|
+
}
|
704
|
+
|
705
|
+
/**
|
706
|
+
* Removes a role from a member.
|
707
|
+
* @param {UserResolvable} user The user to remove the role from
|
708
|
+
* @param {RoleResolvable} role The role to remove
|
709
|
+
* @param {string} [reason] Reason for removing the role
|
710
|
+
* @returns {Promise<GuildMember|User|Snowflake>}
|
711
|
+
*/
|
712
|
+
async removeRole(user, role, reason) {
|
713
|
+
const userId = this.guild.members.resolveId(user);
|
714
|
+
const roleId = this.guild.roles.resolveId(role);
|
715
|
+
|
716
|
+
await this.client.api.guilds(this.guild.id).members(userId).roles(roleId).delete({ reason });
|
717
|
+
|
718
|
+
return this.resolve(user) ?? this.client.users.resolve(user) ?? userId;
|
719
|
+
}
|
720
|
+
|
721
|
+
_fetchMany({
|
722
|
+
limit = 0,
|
723
|
+
withPresences: presences = true,
|
724
|
+
user: user_ids,
|
725
|
+
query,
|
726
|
+
time = 120e3,
|
727
|
+
nonce = SnowflakeUtil.generate(),
|
728
|
+
} = {}) {
|
729
|
+
return new Promise((resolve, reject) => {
|
730
|
+
if (!query && !user_ids) query = '';
|
731
|
+
if (nonce.length > 32) throw new RangeError('MEMBER_FETCH_NONCE_LENGTH');
|
732
|
+
this.guild.shard.send({
|
733
|
+
op: Opcodes.REQUEST_GUILD_MEMBERS,
|
734
|
+
d: {
|
735
|
+
guild_id: this.guild.id,
|
736
|
+
presences,
|
737
|
+
user_ids,
|
738
|
+
query,
|
739
|
+
nonce,
|
740
|
+
limit,
|
741
|
+
},
|
742
|
+
});
|
743
|
+
const fetchedMembers = new Collection();
|
744
|
+
let i = 0;
|
745
|
+
const handler = (members, _, chunk) => {
|
746
|
+
timeout.refresh();
|
747
|
+
if (chunk.nonce !== nonce) return;
|
748
|
+
i++;
|
749
|
+
for (const member of members.values()) {
|
750
|
+
fetchedMembers.set(member.id, member);
|
751
|
+
}
|
752
|
+
if (members.size < 1_000 || (limit && fetchedMembers.size >= limit) || i === chunk.count) {
|
753
|
+
clearTimeout(timeout);
|
754
|
+
this.client.removeListener(Events.GUILD_MEMBERS_CHUNK, handler);
|
755
|
+
this.client.decrementMaxListeners();
|
756
|
+
let fetched = fetchedMembers;
|
757
|
+
if (user_ids && !Array.isArray(user_ids) && fetched.size) fetched = fetched.first();
|
758
|
+
resolve(fetched);
|
759
|
+
}
|
760
|
+
};
|
761
|
+
const timeout = setTimeout(() => {
|
762
|
+
this.client.removeListener(Events.GUILD_MEMBERS_CHUNK, handler);
|
763
|
+
this.client.decrementMaxListeners();
|
764
|
+
reject(new Error('GUILD_MEMBERS_TIMEOUT'));
|
765
|
+
}, time).unref();
|
766
|
+
this.client.incrementMaxListeners();
|
767
|
+
this.client.on(Events.GUILD_MEMBERS_CHUNK, handler);
|
768
|
+
});
|
769
|
+
}
|
770
|
+
}
|
771
|
+
|
772
|
+
module.exports = GuildMemberManager;
|