discord-selfbot-v13.js 0.0.1-security → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of discord-selfbot-v13.js might be problematic. Click here for more details.
- package/LICENSE +674 -0
- package/README.md +128 -5
- package/package.json +98 -3
- package/src/WebSocket.js +39 -0
- package/src/client/BaseClient.js +87 -0
- package/src/client/Client.js +1124 -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/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,730 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const { Collection } = require('@discordjs/collection');
|
4
|
+
const Base = require('./Base');
|
5
|
+
const ClientApplication = require('./ClientApplication');
|
6
|
+
const VoiceState = require('./VoiceState');
|
7
|
+
const TextBasedChannel = require('./interfaces/TextBasedChannel');
|
8
|
+
const { Error } = require('../errors');
|
9
|
+
const { RelationshipTypes, NitroType } = require('../util/Constants');
|
10
|
+
const SnowflakeUtil = require('../util/SnowflakeUtil');
|
11
|
+
const UserFlags = require('../util/UserFlags');
|
12
|
+
const Util = require('../util/Util');
|
13
|
+
|
14
|
+
/**
|
15
|
+
* Represents a user on Discord.
|
16
|
+
* @implements {TextBasedChannel}
|
17
|
+
* @extends {Base}
|
18
|
+
*/
|
19
|
+
class User extends Base {
|
20
|
+
constructor(client, data, application) {
|
21
|
+
super(client);
|
22
|
+
/**
|
23
|
+
* The user's id
|
24
|
+
* @type {Snowflake}
|
25
|
+
*/
|
26
|
+
this.id = data.id;
|
27
|
+
|
28
|
+
this.bot = null;
|
29
|
+
|
30
|
+
this.system = null;
|
31
|
+
|
32
|
+
this.flags = null;
|
33
|
+
|
34
|
+
/**
|
35
|
+
* An array of object (connected accounts), containing the following properties:
|
36
|
+
* @property {string} type The account type (twitch, youtube, etc)
|
37
|
+
* @property {string} name The account name
|
38
|
+
* @property {string} id The account id
|
39
|
+
* @property {boolean} verified Whether the account is verified
|
40
|
+
* @see {@link https://discord.com/developers/docs/resources/user#connection-object}
|
41
|
+
* @typedef {Object} ConnectionAccount
|
42
|
+
*/
|
43
|
+
|
44
|
+
/**
|
45
|
+
* Accounts connected to this user
|
46
|
+
* <info>The user must be force fetched for this property to be present or be updated</info>
|
47
|
+
* @type {?ConnectionAccount[]}
|
48
|
+
*/
|
49
|
+
this.connectedAccounts = [];
|
50
|
+
/**
|
51
|
+
* Time that User has nitro (Unix Timestamp)
|
52
|
+
* <info>The user must be force fetched for this property to be present or be updated</info>
|
53
|
+
* @type {?number}
|
54
|
+
*/
|
55
|
+
this.premiumSince = null;
|
56
|
+
/**
|
57
|
+
* Time that User has nitro and boost server (Unix Timestamp)
|
58
|
+
* @type {?number}
|
59
|
+
*/
|
60
|
+
this.premiumGuildSince = null;
|
61
|
+
/**
|
62
|
+
* About me (User)
|
63
|
+
* <info>The user must be force fetched for this property to be present or be updated</info>
|
64
|
+
* @type {?string}
|
65
|
+
*/
|
66
|
+
this.bio = null;
|
67
|
+
/**
|
68
|
+
* Pronouns (User)
|
69
|
+
* <info>The user must be force fetched for this property to be present or be updated</info>
|
70
|
+
* @type {?string}
|
71
|
+
*/
|
72
|
+
this.pronouns = null;
|
73
|
+
this._mutualGuilds = [];
|
74
|
+
/**
|
75
|
+
* [Bot] Application
|
76
|
+
* @type {?ClientApplication}
|
77
|
+
*/
|
78
|
+
this.application = application ? new ClientApplication(this.client, application, this) : null;
|
79
|
+
this._partial = true;
|
80
|
+
this._patch(data);
|
81
|
+
}
|
82
|
+
|
83
|
+
_patch(data) {
|
84
|
+
if ('username' in data) {
|
85
|
+
/**
|
86
|
+
* The username of the user
|
87
|
+
* @type {?string}
|
88
|
+
*/
|
89
|
+
this.username = data.username;
|
90
|
+
} else {
|
91
|
+
this.username ??= null;
|
92
|
+
}
|
93
|
+
|
94
|
+
if ('global_name' in data) {
|
95
|
+
/**
|
96
|
+
* The global name of this user
|
97
|
+
* @type {?string}
|
98
|
+
*/
|
99
|
+
this.globalName = data.global_name;
|
100
|
+
} else {
|
101
|
+
this.globalName ??= null;
|
102
|
+
}
|
103
|
+
|
104
|
+
if ('bot' in data) {
|
105
|
+
/**
|
106
|
+
* Whether or not the user is a bot
|
107
|
+
* @type {?boolean}
|
108
|
+
*/
|
109
|
+
this.bot = Boolean(data.bot);
|
110
|
+
if (this.bot === true && !this.application) {
|
111
|
+
this.application = new ClientApplication(this.client, { id: this.id }, this);
|
112
|
+
this.botInGuildsCount = null;
|
113
|
+
}
|
114
|
+
} else if (!this.partial && typeof this.bot !== 'boolean') {
|
115
|
+
this.bot = false;
|
116
|
+
}
|
117
|
+
|
118
|
+
if ('discriminator' in data) {
|
119
|
+
/**
|
120
|
+
* The discriminator of this user
|
121
|
+
* <info>`'0'`, or a 4-digit stringified number if they're using the legacy username system</info>
|
122
|
+
* @type {?string}
|
123
|
+
*/
|
124
|
+
this.discriminator = data.discriminator;
|
125
|
+
} else {
|
126
|
+
this.discriminator ??= null;
|
127
|
+
}
|
128
|
+
|
129
|
+
if ('avatar' in data) {
|
130
|
+
/**
|
131
|
+
* The user avatar's hash
|
132
|
+
* @type {?string}
|
133
|
+
*/
|
134
|
+
this.avatar = data.avatar;
|
135
|
+
} else {
|
136
|
+
this.avatar ??= null;
|
137
|
+
}
|
138
|
+
|
139
|
+
if ('banner' in data) {
|
140
|
+
/**
|
141
|
+
* The user banner's hash
|
142
|
+
* <info>The user must be force fetched for this property to be present or be updated</info>
|
143
|
+
* @type {?string}
|
144
|
+
*/
|
145
|
+
this.banner = data.banner;
|
146
|
+
} else if (this.banner !== null) {
|
147
|
+
this.banner ??= undefined;
|
148
|
+
}
|
149
|
+
|
150
|
+
if ('accent_color' in data) {
|
151
|
+
/**
|
152
|
+
* The base 10 accent color of the user's banner
|
153
|
+
* <info>The user must be force fetched for this property to be present or be updated</info>
|
154
|
+
* @type {?number}
|
155
|
+
*/
|
156
|
+
this.accentColor = data.accent_color;
|
157
|
+
} else if (this.accentColor !== null) {
|
158
|
+
this.accentColor ??= undefined;
|
159
|
+
}
|
160
|
+
|
161
|
+
if ('system' in data) {
|
162
|
+
/**
|
163
|
+
* Whether the user is an Official Discord System user (part of the urgent message system)
|
164
|
+
* @type {?boolean}
|
165
|
+
*/
|
166
|
+
this.system = Boolean(data.system);
|
167
|
+
} else if (!this.partial && typeof this.system !== 'boolean') {
|
168
|
+
this.system = false;
|
169
|
+
}
|
170
|
+
|
171
|
+
if ('public_flags' in data) {
|
172
|
+
/**
|
173
|
+
* The flags for this user
|
174
|
+
* @type {?UserFlags}
|
175
|
+
*/
|
176
|
+
this.flags = new UserFlags(data.public_flags);
|
177
|
+
}
|
178
|
+
|
179
|
+
if ('approximate_guild_count' in data) {
|
180
|
+
/**
|
181
|
+
* Check how many guilds the bot is in (Probably only approximate) (application.fetch() first)
|
182
|
+
* @type {?number}
|
183
|
+
*/
|
184
|
+
this.botInGuildsCount = data.approximate_guild_count;
|
185
|
+
}
|
186
|
+
|
187
|
+
if ('avatar_decoration' in data) {
|
188
|
+
/**
|
189
|
+
* The user avatar decoration's hash
|
190
|
+
* @type {?string}
|
191
|
+
*/
|
192
|
+
this.avatarDecoration = data.avatar_decoration;
|
193
|
+
} else {
|
194
|
+
this.avatarDecoration ??= null;
|
195
|
+
}
|
196
|
+
}
|
197
|
+
|
198
|
+
/**
|
199
|
+
* This user is on the same servers as Client User
|
200
|
+
* <info>The user must be force fetched for this property to be present or be updated</info>
|
201
|
+
* @type {Collection<Snowflake, Guild>}
|
202
|
+
* @readonly
|
203
|
+
*/
|
204
|
+
get mutualGuilds() {
|
205
|
+
return new Collection(this._mutualGuilds.map(obj => [obj.id, obj]));
|
206
|
+
}
|
207
|
+
|
208
|
+
/**
|
209
|
+
* Get all mutual friends (Client -> User)
|
210
|
+
* @type {Promise<Collection<Snowflake, User>>}
|
211
|
+
* @readonly
|
212
|
+
*/
|
213
|
+
get mutualFriends() {
|
214
|
+
// eslint-disable-next-line no-async-promise-executor
|
215
|
+
return new Promise(async resolve => {
|
216
|
+
const all = new Collection();
|
217
|
+
if (this.bot || this.client.user.id === this.id) return resolve(all);
|
218
|
+
const data = await this.client.api.users(this.id).relationships.get();
|
219
|
+
for (const u of data) {
|
220
|
+
all.set(u.id, this.client.users._add(u));
|
221
|
+
}
|
222
|
+
return resolve(all);
|
223
|
+
});
|
224
|
+
}
|
225
|
+
|
226
|
+
/**
|
227
|
+
* Check relationship status (Client -> User)
|
228
|
+
* @type {RelationshipTypes}
|
229
|
+
* @readonly
|
230
|
+
*/
|
231
|
+
get relationships() {
|
232
|
+
const i = this.client.relationships.cache.get(this.id) ?? 0;
|
233
|
+
return RelationshipTypes[parseInt(i)];
|
234
|
+
}
|
235
|
+
|
236
|
+
/**
|
237
|
+
* Check note
|
238
|
+
* @type {?string}
|
239
|
+
* @readonly
|
240
|
+
*/
|
241
|
+
get note() {
|
242
|
+
return this.client.user.notes.get(this.id);
|
243
|
+
}
|
244
|
+
|
245
|
+
/**
|
246
|
+
* Get friend nickname
|
247
|
+
* @type {?string}
|
248
|
+
* @readonly
|
249
|
+
*/
|
250
|
+
get nickname() {
|
251
|
+
return this.client.user.friendNicknames.get(this.id);
|
252
|
+
}
|
253
|
+
|
254
|
+
/**
|
255
|
+
* The voice state of this member
|
256
|
+
* @type {VoiceState}
|
257
|
+
* @readonly
|
258
|
+
*/
|
259
|
+
get voice() {
|
260
|
+
return (
|
261
|
+
this.client.voiceStates.cache.get(this.id) ??
|
262
|
+
this.client.guilds.cache.find(g => g?.voiceStates?.cache?.get(this.id))?.voiceStates?.cache?.get(this.id) ??
|
263
|
+
new VoiceState({ client: this.client }, { user_id: this.id })
|
264
|
+
);
|
265
|
+
}
|
266
|
+
|
267
|
+
_ProfilePatch(data) {
|
268
|
+
if (!data) return;
|
269
|
+
|
270
|
+
this._partial = false;
|
271
|
+
|
272
|
+
if (data.connected_accounts.length > 0) {
|
273
|
+
this.connectedAccounts = data.connected_accounts;
|
274
|
+
}
|
275
|
+
|
276
|
+
if ('premium_since' in data) {
|
277
|
+
const date = new Date(data.premium_since);
|
278
|
+
this.premiumSince = date.getTime();
|
279
|
+
}
|
280
|
+
|
281
|
+
if ('premium_guild_since' in data) {
|
282
|
+
const date = new Date(data.premium_guild_since);
|
283
|
+
this.premiumGuildSince = date.getTime();
|
284
|
+
}
|
285
|
+
|
286
|
+
if ('premium_type' in data) {
|
287
|
+
const nitro = NitroType[data.premium_type ?? 0];
|
288
|
+
/**
|
289
|
+
* Nitro type of the user.
|
290
|
+
* @type {NitroType}
|
291
|
+
*/
|
292
|
+
this.nitroType = nitro ?? `UNKNOWN_TYPE_${data.premium_type}`;
|
293
|
+
}
|
294
|
+
|
295
|
+
if ('user_profile' in data) {
|
296
|
+
this.bio = data.user_profile.bio;
|
297
|
+
/**
|
298
|
+
* The user's theme colors (Profile theme) [Primary, Accent]
|
299
|
+
* <info>The user must be force fetched for this property to be present or be updated</info>
|
300
|
+
* @type {?Array<number>}
|
301
|
+
*/
|
302
|
+
this.themeColors = data.user_profile.theme_colors;
|
303
|
+
|
304
|
+
this.pronouns = data.user_profile.pronouns;
|
305
|
+
}
|
306
|
+
|
307
|
+
if ('guild_member_profile' in data && 'guild_member' in data) {
|
308
|
+
const guild = this.client.guilds.cache.get(data.guild_member_profile.guild_id);
|
309
|
+
const member = guild?.members._add(data.guild_member);
|
310
|
+
member._ProfilePatch(data.guild_member_profile);
|
311
|
+
}
|
312
|
+
|
313
|
+
if ('application' in data) {
|
314
|
+
this.application = new ClientApplication(this.client, data.application, this);
|
315
|
+
}
|
316
|
+
|
317
|
+
if ('badges' in data) {
|
318
|
+
/**
|
319
|
+
* @callback BadgeIcon
|
320
|
+
* @returns {string}
|
321
|
+
*/
|
322
|
+
|
323
|
+
/**
|
324
|
+
* @typedef {Object} UserBadge
|
325
|
+
* @property {string} id The id of the badge
|
326
|
+
* @property {string} description The description of the badge
|
327
|
+
* @property {string} icon The icon hash of the badge
|
328
|
+
* @property {?string} link The link of the badge
|
329
|
+
* @property {BadgeIcon} iconURL The iconURL of the badge
|
330
|
+
*/
|
331
|
+
|
332
|
+
/**
|
333
|
+
* User badges (Boost, Slash, AutoMod, etc.)
|
334
|
+
* @type {?Array<UserBadge>}
|
335
|
+
*/
|
336
|
+
this.badges = data.badges.map(o => ({ ...o, iconURL: () => this.client.rest.cdn.BadgeIcon(o.icon) }));
|
337
|
+
}
|
338
|
+
|
339
|
+
if ('guild_badges' in data) {
|
340
|
+
// Unknown
|
341
|
+
}
|
342
|
+
|
343
|
+
if ('mutual_guilds' in data) {
|
344
|
+
this._mutualGuilds = data.mutual_guilds;
|
345
|
+
}
|
346
|
+
}
|
347
|
+
|
348
|
+
/**
|
349
|
+
* Get profile from Discord, if client is in a server with the target.
|
350
|
+
* @type {User}
|
351
|
+
* @param {Snowflake | null} guildId The guild id to get the profile from
|
352
|
+
* @returns {Promise<User>}
|
353
|
+
*/
|
354
|
+
async getProfile(guildId) {
|
355
|
+
if (this.client.bot) throw new Error('INVALID_BOT_METHOD');
|
356
|
+
const query = guildId
|
357
|
+
? {
|
358
|
+
with_mutual_guilds: true,
|
359
|
+
guild_id: guildId,
|
360
|
+
}
|
361
|
+
: {
|
362
|
+
with_mutual_guilds: true,
|
363
|
+
};
|
364
|
+
const data = await this.client.api.users(this.id).profile.get({
|
365
|
+
query,
|
366
|
+
});
|
367
|
+
this._ProfilePatch(data);
|
368
|
+
return this;
|
369
|
+
}
|
370
|
+
|
371
|
+
/**
|
372
|
+
* Friends the user [If incoming request]
|
373
|
+
* @type {boolean}
|
374
|
+
* @returns {Promise<boolean>}
|
375
|
+
*/
|
376
|
+
setFriend() {
|
377
|
+
return this.client.relationships.addFriend(this);
|
378
|
+
}
|
379
|
+
|
380
|
+
/**
|
381
|
+
* Changes the nickname of the friend
|
382
|
+
* @param {?string} nickname The nickname to change
|
383
|
+
* @type {boolean}
|
384
|
+
* @returns {Promise<boolean>}
|
385
|
+
*/
|
386
|
+
setNickname(nickname) {
|
387
|
+
return this.client.relationships.setNickname(this.id, nickname);
|
388
|
+
}
|
389
|
+
|
390
|
+
/**
|
391
|
+
* Send Friend Request to the user
|
392
|
+
* @type {boolean}
|
393
|
+
* @returns {Promise<boolean>}
|
394
|
+
*/
|
395
|
+
sendFriendRequest() {
|
396
|
+
return this.client.relationships.sendFriendRequest(this.username, this.discriminator);
|
397
|
+
}
|
398
|
+
/**
|
399
|
+
* Blocks the user
|
400
|
+
* @type {boolean}
|
401
|
+
* @returns {Promise<boolean>}
|
402
|
+
*/
|
403
|
+
setBlock() {
|
404
|
+
return this.client.relationships.addBlocked(this);
|
405
|
+
}
|
406
|
+
|
407
|
+
/**
|
408
|
+
* Removes the user from your blocks list
|
409
|
+
* @type {boolean}
|
410
|
+
* @returns {Promise<boolean>}
|
411
|
+
*/
|
412
|
+
unBlock() {
|
413
|
+
return this.client.relationships.deleteBlocked(this);
|
414
|
+
}
|
415
|
+
|
416
|
+
/**
|
417
|
+
* Removes the user from your friends list
|
418
|
+
* @type {boolean}
|
419
|
+
* @returns {Promise<boolean>}
|
420
|
+
*/
|
421
|
+
unFriend() {
|
422
|
+
return this.client.relationships.deleteFriend(this);
|
423
|
+
}
|
424
|
+
|
425
|
+
/**
|
426
|
+
* Whether this User is a partial
|
427
|
+
* @type {boolean}
|
428
|
+
* @readonly
|
429
|
+
*/
|
430
|
+
get partial() {
|
431
|
+
return typeof this.username !== 'string';
|
432
|
+
}
|
433
|
+
|
434
|
+
/**
|
435
|
+
* The timestamp the user was created at
|
436
|
+
* @type {number}
|
437
|
+
* @readonly
|
438
|
+
*/
|
439
|
+
get createdTimestamp() {
|
440
|
+
return SnowflakeUtil.timestampFrom(this.id);
|
441
|
+
}
|
442
|
+
|
443
|
+
/**
|
444
|
+
* The time the user was created at
|
445
|
+
* @type {Date}
|
446
|
+
* @readonly
|
447
|
+
*/
|
448
|
+
get createdAt() {
|
449
|
+
return new Date(this.createdTimestamp);
|
450
|
+
}
|
451
|
+
|
452
|
+
/**
|
453
|
+
* A link to the user's avatar.
|
454
|
+
* @param {ImageURLOptions} [options={}] Options for the Image URL
|
455
|
+
* @returns {?string}
|
456
|
+
*/
|
457
|
+
avatarURL({ format, size, dynamic } = {}) {
|
458
|
+
if (!this.avatar) return null;
|
459
|
+
return this.client.rest.cdn.Avatar(this.id, this.avatar, format, size, dynamic);
|
460
|
+
}
|
461
|
+
|
462
|
+
/**
|
463
|
+
* A link to the user's avatar decoration.
|
464
|
+
* @param {StaticImageURLOptions} [options={}] Options for the image URL
|
465
|
+
* @returns {?string}
|
466
|
+
*/
|
467
|
+
avatarDecorationURL({ format, size } = {}) {
|
468
|
+
if (!this.avatarDecoration) return null;
|
469
|
+
return this.client.rest.cdn.AvatarDecoration(this.id, this.avatarDecoration, format, size);
|
470
|
+
}
|
471
|
+
|
472
|
+
/**
|
473
|
+
* A link to the user's default avatar
|
474
|
+
* @type {string}
|
475
|
+
* @readonly
|
476
|
+
*/
|
477
|
+
get defaultAvatarURL() {
|
478
|
+
const index = this.discriminator === '0' ? Util.calculateUserDefaultAvatarIndex(this.id) : this.discriminator % 5;
|
479
|
+
return this.client.rest.cdn.DefaultAvatar(index);
|
480
|
+
}
|
481
|
+
|
482
|
+
/**
|
483
|
+
* A link to the user's avatar if they have one.
|
484
|
+
* Otherwise a link to their default avatar will be returned.
|
485
|
+
* @param {ImageURLOptions} [options={}] Options for the Image URL
|
486
|
+
* @returns {string}
|
487
|
+
*/
|
488
|
+
displayAvatarURL(options) {
|
489
|
+
return this.avatarURL(options) ?? this.defaultAvatarURL;
|
490
|
+
}
|
491
|
+
|
492
|
+
/**
|
493
|
+
* The hexadecimal version of the user accent color, with a leading hash
|
494
|
+
* <info>The user must be force fetched for this property to be present</info>
|
495
|
+
* @type {?string}
|
496
|
+
* @readonly
|
497
|
+
*/
|
498
|
+
get hexAccentColor() {
|
499
|
+
if (typeof this.accentColor !== 'number') return this.accentColor;
|
500
|
+
return `#${this.accentColor.toString(16).padStart(6, '0')}`;
|
501
|
+
}
|
502
|
+
|
503
|
+
/**
|
504
|
+
* A link to the user's banner.
|
505
|
+
* <info>This method will throw an error if called before the user is force fetched.
|
506
|
+
* See {@link User#banner} for more info</info>
|
507
|
+
* @param {ImageURLOptions} [options={}] Options for the Image URL
|
508
|
+
* @returns {?string}
|
509
|
+
*/
|
510
|
+
bannerURL({ format, size, dynamic } = {}) {
|
511
|
+
if (typeof this.banner === 'undefined') {
|
512
|
+
throw new Error('USER_BANNER_NOT_FETCHED');
|
513
|
+
}
|
514
|
+
if (!this.banner) return null;
|
515
|
+
return this.client.rest.cdn.Banner(this.id, this.banner, format, size, dynamic);
|
516
|
+
}
|
517
|
+
|
518
|
+
/**
|
519
|
+
* Ring the user's phone / PC (call)
|
520
|
+
* @returns {Promise<any>}
|
521
|
+
* @deprecated
|
522
|
+
*/
|
523
|
+
ring() {
|
524
|
+
if (this.relationships !== 'FRIEND') return Promise.reject(new Error('USER_NOT_FRIEND'));
|
525
|
+
if (!this.client.user.voice?.channelId || !this.client.callVoice) {
|
526
|
+
return Promise.reject(new Error('CLIENT_NO_CALL'));
|
527
|
+
}
|
528
|
+
return this.client.api.channels(this.dmChannel.id).call.ring.post({
|
529
|
+
data: {
|
530
|
+
recipients: [this.id],
|
531
|
+
},
|
532
|
+
});
|
533
|
+
}
|
534
|
+
|
535
|
+
/**
|
536
|
+
* The hexadecimal version of the user theme color, with a leading hash [Primary, Accent]
|
537
|
+
* <info>The user must be force fetched for this property to be present or be updated</info>
|
538
|
+
* @type {?Array<string>}
|
539
|
+
* @readonly
|
540
|
+
*/
|
541
|
+
get hexThemeColor() {
|
542
|
+
return this.themeColors?.map(c => `#${c.toString(16).padStart(6, '0')}`) || null;
|
543
|
+
}
|
544
|
+
|
545
|
+
/**
|
546
|
+
* The tag of this user
|
547
|
+
* <info>This user's username, or their legacy tag (e.g. `hydrabolt#0001`)
|
548
|
+
* if they're using the legacy username system</info>
|
549
|
+
* @type {?string}
|
550
|
+
* @readonly
|
551
|
+
*/
|
552
|
+
get tag() {
|
553
|
+
return typeof this.username === 'string'
|
554
|
+
? this.discriminator === '0'
|
555
|
+
? this.username
|
556
|
+
: `${this.username}#${this.discriminator}`
|
557
|
+
: null;
|
558
|
+
}
|
559
|
+
|
560
|
+
/**
|
561
|
+
* The global name of this user, or their username if they don't have one
|
562
|
+
* @type {?string}
|
563
|
+
* @readonly
|
564
|
+
*/
|
565
|
+
get displayName() {
|
566
|
+
return this.globalName ?? this.username;
|
567
|
+
}
|
568
|
+
|
569
|
+
/**
|
570
|
+
* The DM between the client's user and this user
|
571
|
+
* @type {?DMChannel}
|
572
|
+
* @readonly
|
573
|
+
*/
|
574
|
+
get dmChannel() {
|
575
|
+
return this.client.users.dmChannel(this.id);
|
576
|
+
}
|
577
|
+
|
578
|
+
/**
|
579
|
+
* Creates a DM channel between the client and the user.
|
580
|
+
* @param {boolean} [force=false] Whether to skip the cache check and request the API
|
581
|
+
* @returns {Promise<DMChannel>}
|
582
|
+
*/
|
583
|
+
createDM(force = false) {
|
584
|
+
return this.client.users.createDM(this.id, force);
|
585
|
+
}
|
586
|
+
|
587
|
+
/**
|
588
|
+
* Deletes a DM channel (if one exists) between the client and the user. Resolves with the channel if successful.
|
589
|
+
* @returns {Promise<DMChannel>}
|
590
|
+
*/
|
591
|
+
deleteDM() {
|
592
|
+
return this.client.users.deleteDM(this.id);
|
593
|
+
}
|
594
|
+
|
595
|
+
/**
|
596
|
+
* Checks if the user is equal to another.
|
597
|
+
* It compares id, username, discriminator, avatar, banner, accent color, and bot flags.
|
598
|
+
* It is recommended to compare equality by using `user.id === user2.id` unless you want to compare all properties.
|
599
|
+
* @param {User} user User to compare with
|
600
|
+
* @returns {boolean}
|
601
|
+
*/
|
602
|
+
equals(user) {
|
603
|
+
return (
|
604
|
+
user &&
|
605
|
+
this.id === user.id &&
|
606
|
+
this.username === user.username &&
|
607
|
+
this.discriminator === user.discriminator &&
|
608
|
+
this.globalName === user.globalName &&
|
609
|
+
this.avatar === user.avatar &&
|
610
|
+
this.flags?.bitfield === user.flags?.bitfield &&
|
611
|
+
this.banner === user.banner &&
|
612
|
+
this.accentColor === user.accentColor &&
|
613
|
+
this.bio === user.bio
|
614
|
+
);
|
615
|
+
}
|
616
|
+
|
617
|
+
/**
|
618
|
+
* Compares the user with an API user object
|
619
|
+
* @param {APIUser} user The API user object to compare
|
620
|
+
* @returns {boolean}
|
621
|
+
* @private
|
622
|
+
*/
|
623
|
+
_equals(user) {
|
624
|
+
return (
|
625
|
+
user &&
|
626
|
+
this.id === user.id &&
|
627
|
+
this.username === user.username &&
|
628
|
+
this.discriminator === user.discriminator &&
|
629
|
+
this.globalName === user.global_name &&
|
630
|
+
this.avatar === user.avatar &&
|
631
|
+
this.flags?.bitfield === user.public_flags &&
|
632
|
+
('banner' in user ? this.banner === user.banner : true) &&
|
633
|
+
('accent_color' in user ? this.accentColor === user.accent_color : true)
|
634
|
+
);
|
635
|
+
}
|
636
|
+
|
637
|
+
/**
|
638
|
+
* Fetches this user's flags.
|
639
|
+
* @param {boolean} [force=false] Whether to skip the cache check and request the API
|
640
|
+
* @returns {Promise<UserFlags>}
|
641
|
+
*/
|
642
|
+
fetchFlags(force = false) {
|
643
|
+
return this.client.users.fetchFlags(this.id, { force });
|
644
|
+
}
|
645
|
+
|
646
|
+
/**
|
647
|
+
* Fetches this user.
|
648
|
+
* @param {boolean} [force=true] Whether to skip the cache check and request the API
|
649
|
+
* @returns {Promise<User>}
|
650
|
+
*/
|
651
|
+
fetch(force = true) {
|
652
|
+
return this.client.users.fetch(this.id, { force });
|
653
|
+
}
|
654
|
+
|
655
|
+
/**
|
656
|
+
* When concatenated with a string, this automatically returns the user's mention instead of the User object.
|
657
|
+
* @returns {string}
|
658
|
+
* @example
|
659
|
+
* // Logs: Hello from <@123456789012345678>!
|
660
|
+
* console.log(`Hello from ${user}!`);
|
661
|
+
*/
|
662
|
+
toString() {
|
663
|
+
return `<@${this.id}>`;
|
664
|
+
}
|
665
|
+
|
666
|
+
toJSON(...props) {
|
667
|
+
const json = super.toJSON(
|
668
|
+
{
|
669
|
+
createdTimestamp: true,
|
670
|
+
defaultAvatarURL: true,
|
671
|
+
hexAccentColor: true,
|
672
|
+
tag: true,
|
673
|
+
},
|
674
|
+
...props,
|
675
|
+
);
|
676
|
+
json.avatarURL = this.avatarURL();
|
677
|
+
json.displayAvatarURL = this.displayAvatarURL();
|
678
|
+
json.bannerURL = this.banner ? this.bannerURL() : this.banner;
|
679
|
+
return json;
|
680
|
+
}
|
681
|
+
|
682
|
+
/**
|
683
|
+
* Set note to user
|
684
|
+
* @param {string} note Note to set
|
685
|
+
* @returns {Promise<User>}
|
686
|
+
*/
|
687
|
+
async setNote(note = null) {
|
688
|
+
await this.client.api.users['@me'].notes(this.id).put({ data: { note } });
|
689
|
+
return this;
|
690
|
+
}
|
691
|
+
|
692
|
+
/**
|
693
|
+
* Get presence (~ v12)
|
694
|
+
* @returns {Promise<Presence | null>}
|
695
|
+
*/
|
696
|
+
async presenceFetch() {
|
697
|
+
let data = null;
|
698
|
+
await Promise.all(
|
699
|
+
this.client.guilds.cache.map(async guild => {
|
700
|
+
const res_ = await guild.presences.resolve(this.id);
|
701
|
+
if (res_) return (data = res_);
|
702
|
+
return true;
|
703
|
+
}),
|
704
|
+
);
|
705
|
+
return data;
|
706
|
+
}
|
707
|
+
}
|
708
|
+
|
709
|
+
/**
|
710
|
+
* Sends a message to this user.
|
711
|
+
* @method send
|
712
|
+
* @memberof User
|
713
|
+
* @instance
|
714
|
+
* @param {string|MessagePayload|MessageOptions} options The options to provide
|
715
|
+
* @returns {Promise<Message>}
|
716
|
+
* @example
|
717
|
+
* // Send a direct message
|
718
|
+
* user.send('Hello!')
|
719
|
+
* .then(message => console.log(`Sent message: ${message.content} to ${user.tag}`))
|
720
|
+
* .catch(console.error);
|
721
|
+
*/
|
722
|
+
|
723
|
+
TextBasedChannel.applyToClass(User);
|
724
|
+
|
725
|
+
module.exports = User;
|
726
|
+
|
727
|
+
/**
|
728
|
+
* @external APIUser
|
729
|
+
* @see {@link https://discord.com/developers/docs/resources/user#user-object}
|
730
|
+
*/
|