@velliajs/discord 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +191 -0
- package/README.md +133 -0
- package/package.json +82 -0
- package/src/client/BaseClient.js +83 -0
- package/src/client/Client.js +591 -0
- package/src/client/WebhookClient.js +103 -0
- package/src/client/actions/Action.js +119 -0
- package/src/client/actions/ActionsManager.js +79 -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 +23 -0
- package/src/client/actions/ChannelUpdate.js +33 -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 +44 -0
- package/src/client/actions/GuildEmojiCreate.js +20 -0
- package/src/client/actions/GuildEmojiDelete.js +19 -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 +31 -0
- package/src/client/actions/GuildMemberUpdate.js +44 -0
- package/src/client/actions/GuildRoleCreate.js +25 -0
- package/src/client/actions/GuildRoleDelete.js +29 -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 +19 -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 +101 -0
- package/src/client/actions/InviteCreate.js +28 -0
- package/src/client/actions/InviteDelete.js +30 -0
- package/src/client/actions/MessageCreate.js +37 -0
- package/src/client/actions/MessageDelete.js +32 -0
- package/src/client/actions/MessageDeleteBulk.js +47 -0
- package/src/client/actions/MessageReactionAdd.js +55 -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 +42 -0
- package/src/client/actions/StageInstanceCreate.js +28 -0
- package/src/client/actions/StageInstanceDelete.js +31 -0
- package/src/client/actions/StageInstanceUpdate.js +30 -0
- package/src/client/actions/ThreadCreate.js +24 -0
- package/src/client/actions/ThreadDelete.js +26 -0
- package/src/client/actions/ThreadListSync.js +60 -0
- package/src/client/actions/ThreadMemberUpdate.js +30 -0
- package/src/client/actions/ThreadMembersUpdate.js +47 -0
- package/src/client/actions/TypingStart.js +29 -0
- package/src/client/actions/UserUpdate.js +36 -0
- package/src/client/actions/VoiceStateUpdate.js +43 -0
- package/src/client/actions/WebhooksUpdate.js +20 -0
- package/src/client/voice/ClientVoiceManager.js +44 -0
- package/src/client/websocket/WebSocketManager.js +393 -0
- package/src/client/websocket/WebSocketShard.js +231 -0
- package/src/client/websocket/handlers/APPLICATION_COMMAND_PERMISSIONS_UPDATE.js +5 -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/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_UPDATE.js +16 -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 +26 -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_REMOVE.js +5 -0
- package/src/client/websocket/handlers/GUILD_MEMBER_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_ROLE_CREATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_ROLE_DELETE.js +5 -0
- package/src/client/websocket/handlers/GUILD_ROLE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_CREATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_DELETE.js +5 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_ADD.js +5 -0
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_USER_REMOVE.js +5 -0
- package/src/client/websocket/handlers/GUILD_STICKERS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/GUILD_UPDATE.js +5 -0
- package/src/client/websocket/handlers/INTERACTION_CREATE.js +5 -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_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 +27 -0
- package/src/client/websocket/handlers/RESUMED.js +14 -0
- package/src/client/websocket/handlers/STAGE_INSTANCE_CREATE.js +5 -0
- package/src/client/websocket/handlers/STAGE_INSTANCE_DELETE.js +5 -0
- package/src/client/websocket/handlers/STAGE_INSTANCE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/THREAD_CREATE.js +5 -0
- package/src/client/websocket/handlers/THREAD_DELETE.js +5 -0
- package/src/client/websocket/handlers/THREAD_LIST_SYNC.js +5 -0
- package/src/client/websocket/handlers/THREAD_MEMBERS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/THREAD_MEMBER_UPDATE.js +5 -0
- package/src/client/websocket/handlers/THREAD_UPDATE.js +16 -0
- package/src/client/websocket/handlers/TYPING_START.js +5 -0
- package/src/client/websocket/handlers/USER_UPDATE.js +5 -0
- package/src/client/websocket/handlers/VOICE_SERVER_UPDATE.js +6 -0
- package/src/client/websocket/handlers/VOICE_STATE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/WEBHOOKS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/index.js +64 -0
- package/src/errors/DJSError.js +48 -0
- package/src/errors/ErrorCodes.js +319 -0
- package/src/errors/Messages.js +170 -0
- package/src/errors/index.js +5 -0
- package/src/index.js +213 -0
- package/src/managers/ApplicationCommandManager.js +263 -0
- package/src/managers/ApplicationCommandPermissionsManager.js +434 -0
- package/src/managers/AutoModerationRuleManager.js +288 -0
- package/src/managers/BaseGuildEmojiManager.js +80 -0
- package/src/managers/BaseManager.js +19 -0
- package/src/managers/CachedManager.js +57 -0
- package/src/managers/CategoryChannelChildManager.js +77 -0
- package/src/managers/ChannelManager.js +128 -0
- package/src/managers/DataManager.js +61 -0
- package/src/managers/GuildApplicationCommandManager.js +28 -0
- package/src/managers/GuildBanManager.js +204 -0
- package/src/managers/GuildChannelManager.js +494 -0
- package/src/managers/GuildEmojiManager.js +174 -0
- package/src/managers/GuildEmojiRoleManager.js +118 -0
- package/src/managers/GuildForumThreadManager.js +83 -0
- package/src/managers/GuildInviteManager.js +213 -0
- package/src/managers/GuildManager.js +283 -0
- package/src/managers/GuildMemberManager.js +540 -0
- package/src/managers/GuildMemberRoleManager.js +204 -0
- package/src/managers/GuildScheduledEventManager.js +297 -0
- package/src/managers/GuildStickerManager.js +182 -0
- package/src/managers/GuildTextThreadManager.js +91 -0
- package/src/managers/MessageManager.js +259 -0
- package/src/managers/PermissionOverwriteManager.js +168 -0
- package/src/managers/PresenceManager.js +58 -0
- package/src/managers/ReactionManager.js +68 -0
- package/src/managers/ReactionUserManager.js +77 -0
- package/src/managers/RoleManager.js +360 -0
- package/src/managers/StageInstanceManager.js +154 -0
- package/src/managers/ThreadManager.js +204 -0
- package/src/managers/ThreadMemberManager.js +182 -0
- package/src/managers/UserManager.js +139 -0
- package/src/managers/VoiceStateManager.js +37 -0
- package/src/sharding/Shard.js +457 -0
- package/src/sharding/ShardClientUtil.js +285 -0
- package/src/sharding/ShardingManager.js +326 -0
- package/src/structures/ActionRow.js +46 -0
- package/src/structures/ActionRowBuilder.js +35 -0
- package/src/structures/AnonymousGuild.js +97 -0
- package/src/structures/ApplicationCommand.js +606 -0
- package/src/structures/ApplicationRoleConnectionMetadata.js +46 -0
- package/src/structures/Attachment.js +140 -0
- package/src/structures/AttachmentBuilder.js +116 -0
- package/src/structures/AutoModerationActionExecution.js +116 -0
- package/src/structures/AutoModerationRule.js +284 -0
- package/src/structures/AutocompleteInteraction.js +97 -0
- package/src/structures/Base.js +43 -0
- package/src/structures/BaseChannel.js +160 -0
- package/src/structures/BaseGuild.js +119 -0
- package/src/structures/BaseGuildEmoji.js +56 -0
- package/src/structures/BaseGuildTextChannel.js +186 -0
- package/src/structures/BaseGuildVoiceChannel.js +234 -0
- package/src/structures/BaseInteraction.js +344 -0
- package/src/structures/BaseSelectMenuComponent.js +56 -0
- package/src/structures/ButtonBuilder.js +44 -0
- package/src/structures/ButtonComponent.js +65 -0
- package/src/structures/ButtonInteraction.js +11 -0
- package/src/structures/CategoryChannel.js +45 -0
- package/src/structures/ChannelSelectMenuBuilder.js +31 -0
- package/src/structures/ChannelSelectMenuComponent.js +20 -0
- package/src/structures/ChannelSelectMenuInteraction.js +33 -0
- package/src/structures/ChatInputCommandInteraction.js +41 -0
- package/src/structures/ClientApplication.js +193 -0
- package/src/structures/ClientPresence.js +82 -0
- package/src/structures/ClientUser.js +185 -0
- package/src/structures/CommandInteraction.js +224 -0
- package/src/structures/CommandInteractionOptionResolver.js +308 -0
- package/src/structures/Component.js +47 -0
- package/src/structures/ContextMenuCommandInteraction.js +64 -0
- package/src/structures/DMChannel.js +129 -0
- package/src/structures/DirectoryChannel.js +36 -0
- package/src/structures/Embed.js +220 -0
- package/src/structures/EmbedBuilder.js +41 -0
- package/src/structures/Emoji.js +108 -0
- package/src/structures/ForumChannel.js +264 -0
- package/src/structures/Guild.js +1361 -0
- package/src/structures/GuildAuditLogs.js +91 -0
- package/src/structures/GuildAuditLogsEntry.js +527 -0
- package/src/structures/GuildBan.js +59 -0
- package/src/structures/GuildChannel.js +457 -0
- package/src/structures/GuildEmoji.js +148 -0
- package/src/structures/GuildMember.js +518 -0
- package/src/structures/GuildPreview.js +193 -0
- package/src/structures/GuildPreviewEmoji.js +27 -0
- package/src/structures/GuildScheduledEvent.js +439 -0
- package/src/structures/GuildTemplate.js +241 -0
- package/src/structures/Integration.js +220 -0
- package/src/structures/IntegrationApplication.js +85 -0
- package/src/structures/InteractionCollector.js +263 -0
- package/src/structures/InteractionResponse.js +102 -0
- package/src/structures/InteractionWebhook.js +59 -0
- package/src/structures/Invite.js +322 -0
- package/src/structures/InviteGuild.js +22 -0
- package/src/structures/InviteStageInstance.js +87 -0
- package/src/structures/MentionableSelectMenuBuilder.js +32 -0
- package/src/structures/MentionableSelectMenuComponent.js +11 -0
- package/src/structures/MentionableSelectMenuInteraction.js +71 -0
- package/src/structures/Message.js +997 -0
- package/src/structures/MessageCollector.js +146 -0
- package/src/structures/MessageComponentInteraction.js +107 -0
- package/src/structures/MessageContextMenuCommandInteraction.js +20 -0
- package/src/structures/MessageMentions.js +297 -0
- package/src/structures/MessagePayload.js +299 -0
- package/src/structures/MessageReaction.js +142 -0
- package/src/structures/ModalBuilder.js +34 -0
- package/src/structures/ModalSubmitFields.js +55 -0
- package/src/structures/ModalSubmitInteraction.js +121 -0
- package/src/structures/NewsChannel.js +32 -0
- package/src/structures/OAuth2Guild.js +28 -0
- package/src/structures/PartialGroupDMChannel.js +60 -0
- package/src/structures/PermissionOverwrites.js +196 -0
- package/src/structures/Presence.js +372 -0
- package/src/structures/ReactionCollector.js +229 -0
- package/src/structures/ReactionEmoji.js +31 -0
- package/src/structures/Role.js +458 -0
- package/src/structures/RoleSelectMenuBuilder.js +31 -0
- package/src/structures/RoleSelectMenuComponent.js +11 -0
- package/src/structures/RoleSelectMenuInteraction.js +33 -0
- package/src/structures/SelectMenuBuilder.js +26 -0
- package/src/structures/SelectMenuComponent.js +26 -0
- package/src/structures/SelectMenuInteraction.js +26 -0
- package/src/structures/SelectMenuOptionBuilder.js +26 -0
- package/src/structures/StageChannel.js +112 -0
- package/src/structures/StageInstance.js +167 -0
- package/src/structures/Sticker.js +272 -0
- package/src/structures/StickerPack.js +95 -0
- package/src/structures/StringSelectMenuBuilder.js +79 -0
- package/src/structures/StringSelectMenuComponent.js +20 -0
- package/src/structures/StringSelectMenuInteraction.js +21 -0
- package/src/structures/StringSelectMenuOptionBuilder.js +49 -0
- package/src/structures/Team.js +117 -0
- package/src/structures/TeamMember.js +70 -0
- package/src/structures/TextChannel.js +33 -0
- package/src/structures/TextInputBuilder.js +31 -0
- package/src/structures/TextInputComponent.js +29 -0
- package/src/structures/ThreadChannel.js +606 -0
- package/src/structures/ThreadMember.js +113 -0
- package/src/structures/Typing.js +74 -0
- package/src/structures/User.js +331 -0
- package/src/structures/UserContextMenuCommandInteraction.js +29 -0
- package/src/structures/UserSelectMenuBuilder.js +31 -0
- package/src/structures/UserSelectMenuComponent.js +11 -0
- package/src/structures/UserSelectMenuInteraction.js +51 -0
- package/src/structures/VoiceChannel.js +96 -0
- package/src/structures/VoiceRegion.js +46 -0
- package/src/structures/VoiceState.js +303 -0
- package/src/structures/Webhook.js +481 -0
- package/src/structures/WelcomeChannel.js +60 -0
- package/src/structures/WelcomeScreen.js +49 -0
- package/src/structures/Widget.js +88 -0
- package/src/structures/WidgetMember.js +99 -0
- package/src/structures/interfaces/Application.js +108 -0
- package/src/structures/interfaces/Collector.js +335 -0
- package/src/structures/interfaces/InteractionResponses.js +320 -0
- package/src/structures/interfaces/TextBasedChannel.js +413 -0
- package/src/util/APITypes.js +456 -0
- package/src/util/ActivityFlagsBitField.js +26 -0
- package/src/util/ApplicationFlagsBitField.js +26 -0
- package/src/util/BitField.js +176 -0
- package/src/util/ChannelFlagsBitField.js +41 -0
- package/src/util/Channels.js +150 -0
- package/src/util/Colors.js +73 -0
- package/src/util/Components.js +152 -0
- package/src/util/Constants.js +230 -0
- package/src/util/DataResolver.js +140 -0
- package/src/util/Enums.js +13 -0
- package/src/util/Events.js +160 -0
- package/src/util/Formatters.js +413 -0
- package/src/util/GuildMemberFlagsBitField.js +41 -0
- package/src/util/IntentsBitField.js +34 -0
- package/src/util/LimitedCollection.js +68 -0
- package/src/util/MessageFlagsBitField.js +32 -0
- package/src/util/Options.js +216 -0
- package/src/util/Partials.js +44 -0
- package/src/util/PermissionsBitField.js +104 -0
- package/src/util/ShardEvents.js +27 -0
- package/src/util/Status.js +33 -0
- package/src/util/Sweepers.js +467 -0
- package/src/util/SystemChannelFlagsBitField.js +43 -0
- package/src/util/ThreadMemberFlagsBitField.js +31 -0
- package/src/util/Transformers.js +36 -0
- package/src/util/UserFlagsBitField.js +32 -0
- package/src/util/Util.js +394 -0
- package/src/util/WebSocketShardEvents.js +25 -0
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { Routes } = require('discord-api-types/v10');
|
|
4
|
+
const User = require('./User');
|
|
5
|
+
const DataResolver = require('../util/DataResolver');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Represents the logged in client's Discord user.
|
|
9
|
+
* @extends {User}
|
|
10
|
+
*/
|
|
11
|
+
class ClientUser extends User {
|
|
12
|
+
_patch(data) {
|
|
13
|
+
super._patch(data);
|
|
14
|
+
|
|
15
|
+
if ('verified' in data) {
|
|
16
|
+
/**
|
|
17
|
+
* Whether or not this account has been verified
|
|
18
|
+
* @type {boolean}
|
|
19
|
+
*/
|
|
20
|
+
this.verified = data.verified;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if ('mfa_enabled' in data) {
|
|
24
|
+
/**
|
|
25
|
+
* If the bot's {@link ClientApplication#owner Owner} has MFA enabled on their account
|
|
26
|
+
* @type {?boolean}
|
|
27
|
+
*/
|
|
28
|
+
this.mfaEnabled = typeof data.mfa_enabled === 'boolean' ? data.mfa_enabled : null;
|
|
29
|
+
} else {
|
|
30
|
+
this.mfaEnabled ??= null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if ('token' in data) this.client.token = data.token;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Represents the client user's presence
|
|
38
|
+
* @type {ClientPresence}
|
|
39
|
+
* @readonly
|
|
40
|
+
*/
|
|
41
|
+
get presence() {
|
|
42
|
+
return this.client.presence;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Data used to edit the logged in client
|
|
47
|
+
* @typedef {Object} ClientUserEditOptions
|
|
48
|
+
* @property {string} [username] The new username
|
|
49
|
+
* @property {?(BufferResolvable|Base64Resolvable)} [avatar] The new avatar
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Edits the logged in client.
|
|
54
|
+
* @param {ClientUserEditOptions} options The options to provide
|
|
55
|
+
* @returns {Promise<ClientUser>}
|
|
56
|
+
*/
|
|
57
|
+
async edit({ username, avatar }) {
|
|
58
|
+
const data = await this.client.rest.patch(Routes.user(), {
|
|
59
|
+
body: { username, avatar: avatar && (await DataResolver.resolveImage(avatar)) },
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
this.client.token = data.token;
|
|
63
|
+
this.client.rest.setToken(data.token);
|
|
64
|
+
const { updated } = this.client.actions.UserUpdate.handle(data);
|
|
65
|
+
return updated ?? this;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Sets the username of the logged in client.
|
|
70
|
+
* <info>Changing usernames in Discord is heavily rate limited, with only 2 requests
|
|
71
|
+
* every hour. Use this sparingly!</info>
|
|
72
|
+
* @param {string} username The new username
|
|
73
|
+
* @returns {Promise<ClientUser>}
|
|
74
|
+
* @example
|
|
75
|
+
* // Set username
|
|
76
|
+
* client.user.setUsername('discordjs')
|
|
77
|
+
* .then(user => console.log(`My new username is ${user.username}`))
|
|
78
|
+
* .catch(console.error);
|
|
79
|
+
*/
|
|
80
|
+
setUsername(username) {
|
|
81
|
+
return this.edit({ username });
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Sets the avatar of the logged in client.
|
|
86
|
+
* @param {?(BufferResolvable|Base64Resolvable)} avatar The new avatar
|
|
87
|
+
* @returns {Promise<ClientUser>}
|
|
88
|
+
* @example
|
|
89
|
+
* // Set avatar
|
|
90
|
+
* client.user.setAvatar('./avatar.png')
|
|
91
|
+
* .then(user => console.log(`New avatar set!`))
|
|
92
|
+
* .catch(console.error);
|
|
93
|
+
*/
|
|
94
|
+
setAvatar(avatar) {
|
|
95
|
+
return this.edit({ avatar });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Options for setting activities
|
|
100
|
+
* @typedef {Object} ActivitiesOptions
|
|
101
|
+
* @property {string} [name] Name of the activity
|
|
102
|
+
* @property {ActivityType} [type] Type of the activity
|
|
103
|
+
* @property {string} [url] Twitch / YouTube stream URL
|
|
104
|
+
*/
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Data resembling a raw Discord presence.
|
|
108
|
+
* @typedef {Object} PresenceData
|
|
109
|
+
* @property {PresenceStatusData} [status] Status of the user
|
|
110
|
+
* @property {boolean} [afk] Whether the user is AFK
|
|
111
|
+
* @property {ActivitiesOptions[]} [activities] Activity the user is playing
|
|
112
|
+
* @property {number|number[]} [shardId] Shard id(s) to have the activity set on
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Sets the full presence of the client user.
|
|
117
|
+
* @param {PresenceData} data Data for the presence
|
|
118
|
+
* @returns {ClientPresence}
|
|
119
|
+
* @example
|
|
120
|
+
* // Set the client user's presence
|
|
121
|
+
* client.user.setPresence({ activities: [{ name: 'with discord.js' }], status: 'idle' });
|
|
122
|
+
*/
|
|
123
|
+
setPresence(data) {
|
|
124
|
+
return this.client.presence.set(data);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* A user's status. Must be one of:
|
|
129
|
+
* * `online`
|
|
130
|
+
* * `idle`
|
|
131
|
+
* * `invisible`
|
|
132
|
+
* * `dnd` (do not disturb)
|
|
133
|
+
* @typedef {string} PresenceStatusData
|
|
134
|
+
*/
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Sets the status of the client user.
|
|
138
|
+
* @param {PresenceStatusData} status Status to change to
|
|
139
|
+
* @param {number|number[]} [shardId] Shard id(s) to have the activity set on
|
|
140
|
+
* @returns {ClientPresence}
|
|
141
|
+
* @example
|
|
142
|
+
* // Set the client user's status
|
|
143
|
+
* client.user.setStatus('idle');
|
|
144
|
+
*/
|
|
145
|
+
setStatus(status, shardId) {
|
|
146
|
+
return this.setPresence({ status, shardId });
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Options for setting an activity.
|
|
151
|
+
* @typedef {Object} ActivityOptions
|
|
152
|
+
* @property {string} [name] Name of the activity
|
|
153
|
+
* @property {string} [url] Twitch / YouTube stream URL
|
|
154
|
+
* @property {ActivityType} [type] Type of the activity
|
|
155
|
+
* @property {number|number[]} [shardId] Shard Id(s) to have the activity set on
|
|
156
|
+
*/
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Sets the activity the client user is playing.
|
|
160
|
+
* @param {string|ActivityOptions} [name] Activity being played, or options for setting the activity
|
|
161
|
+
* @param {ActivityOptions} [options] Options for setting the activity
|
|
162
|
+
* @returns {ClientPresence}
|
|
163
|
+
* @example
|
|
164
|
+
* // Set the client user's activity
|
|
165
|
+
* client.user.setActivity('discord.js', { type: ActivityType.Watching });
|
|
166
|
+
*/
|
|
167
|
+
setActivity(name, options = {}) {
|
|
168
|
+
if (!name) return this.setPresence({ activities: [], shardId: options.shardId });
|
|
169
|
+
|
|
170
|
+
const activity = Object.assign({}, options, typeof name === 'object' ? name : { name });
|
|
171
|
+
return this.setPresence({ activities: [activity], shardId: activity.shardId });
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Sets/removes the AFK flag for the client user.
|
|
176
|
+
* @param {boolean} [afk=true] Whether or not the user is AFK
|
|
177
|
+
* @param {number|number[]} [shardId] Shard Id(s) to have the AFK flag set on
|
|
178
|
+
* @returns {ClientPresence}
|
|
179
|
+
*/
|
|
180
|
+
setAFK(afk = true, shardId) {
|
|
181
|
+
return this.setPresence({ afk, shardId });
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
module.exports = ClientUser;
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { Collection } = require('@discordjs/collection');
|
|
4
|
+
const Attachment = require('./Attachment');
|
|
5
|
+
const BaseInteraction = require('./BaseInteraction');
|
|
6
|
+
const InteractionWebhook = require('./InteractionWebhook');
|
|
7
|
+
const InteractionResponses = require('./interfaces/InteractionResponses');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Represents a command interaction.
|
|
11
|
+
* @extends {BaseInteraction}
|
|
12
|
+
* @implements {InteractionResponses}
|
|
13
|
+
* @abstract
|
|
14
|
+
*/
|
|
15
|
+
class CommandInteraction extends BaseInteraction {
|
|
16
|
+
constructor(client, data) {
|
|
17
|
+
super(client, data);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The id of the channel this interaction was sent in
|
|
21
|
+
* @type {Snowflake}
|
|
22
|
+
* @name CommandInteraction#channelId
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The invoked application command's id
|
|
27
|
+
* @type {Snowflake}
|
|
28
|
+
*/
|
|
29
|
+
this.commandId = data.data.id;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The invoked application command's name
|
|
33
|
+
* @type {string}
|
|
34
|
+
*/
|
|
35
|
+
this.commandName = data.data.name;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The invoked application command's type
|
|
39
|
+
* @type {ApplicationCommandType}
|
|
40
|
+
*/
|
|
41
|
+
this.commandType = data.data.type;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The id of the guild the invoked application command is registered to
|
|
45
|
+
* @type {?Snowflake}
|
|
46
|
+
*/
|
|
47
|
+
this.commandGuildId = data.data.guild_id ?? null;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Whether the reply to this interaction has been deferred
|
|
51
|
+
* @type {boolean}
|
|
52
|
+
*/
|
|
53
|
+
this.deferred = false;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Whether this interaction has already been replied to
|
|
57
|
+
* @type {boolean}
|
|
58
|
+
*/
|
|
59
|
+
this.replied = false;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Whether the reply to this interaction is ephemeral
|
|
63
|
+
* @type {?boolean}
|
|
64
|
+
*/
|
|
65
|
+
this.ephemeral = null;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* An associated interaction webhook, can be used to further interact with this interaction
|
|
69
|
+
* @type {InteractionWebhook}
|
|
70
|
+
*/
|
|
71
|
+
this.webhook = new InteractionWebhook(this.client, this.applicationId, this.token);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The invoked application command, if it was fetched before
|
|
76
|
+
* @type {?ApplicationCommand}
|
|
77
|
+
*/
|
|
78
|
+
get command() {
|
|
79
|
+
const id = this.commandId;
|
|
80
|
+
return this.guild?.commands.cache.get(id) ?? this.client.application.commands.cache.get(id) ?? null;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Represents the resolved data of a received command interaction.
|
|
85
|
+
* @typedef {Object} CommandInteractionResolvedData
|
|
86
|
+
* @property {Collection<Snowflake, User>} [users] The resolved users
|
|
87
|
+
* @property {Collection<Snowflake, GuildMember|APIGuildMember>} [members] The resolved guild members
|
|
88
|
+
* @property {Collection<Snowflake, Role|APIRole>} [roles] The resolved roles
|
|
89
|
+
* @property {Collection<Snowflake, BaseChannel|APIChannel>} [channels] The resolved channels
|
|
90
|
+
* @property {Collection<Snowflake, Message|APIMessage>} [messages] The resolved messages
|
|
91
|
+
* @property {Collection<Snowflake, Attachment>} [attachments] The resolved attachments
|
|
92
|
+
*/
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Transforms the resolved received from the API.
|
|
96
|
+
* @param {APIInteractionDataResolved} resolved The received resolved objects
|
|
97
|
+
* @returns {CommandInteractionResolvedData}
|
|
98
|
+
* @private
|
|
99
|
+
*/
|
|
100
|
+
transformResolved({ members, users, channels, roles, messages, attachments }) {
|
|
101
|
+
const result = {};
|
|
102
|
+
|
|
103
|
+
if (members) {
|
|
104
|
+
result.members = new Collection();
|
|
105
|
+
for (const [id, member] of Object.entries(members)) {
|
|
106
|
+
const user = users[id];
|
|
107
|
+
result.members.set(id, this.guild?.members._add({ user, ...member }) ?? member);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (users) {
|
|
112
|
+
result.users = new Collection();
|
|
113
|
+
for (const user of Object.values(users)) {
|
|
114
|
+
result.users.set(user.id, this.client.users._add(user));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (roles) {
|
|
119
|
+
result.roles = new Collection();
|
|
120
|
+
for (const role of Object.values(roles)) {
|
|
121
|
+
result.roles.set(role.id, this.guild?.roles._add(role) ?? role);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (channels) {
|
|
126
|
+
result.channels = new Collection();
|
|
127
|
+
for (const channel of Object.values(channels)) {
|
|
128
|
+
result.channels.set(channel.id, this.client.channels._add(channel, this.guild) ?? channel);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (messages) {
|
|
133
|
+
result.messages = new Collection();
|
|
134
|
+
for (const message of Object.values(messages)) {
|
|
135
|
+
result.messages.set(message.id, this.channel?.messages?._add(message) ?? message);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (attachments) {
|
|
140
|
+
result.attachments = new Collection();
|
|
141
|
+
for (const attachment of Object.values(attachments)) {
|
|
142
|
+
const patched = new Attachment(attachment);
|
|
143
|
+
result.attachments.set(attachment.id, patched);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Represents an option of a received command interaction.
|
|
152
|
+
* @typedef {Object} CommandInteractionOption
|
|
153
|
+
* @property {string} name The name of the option
|
|
154
|
+
* @property {ApplicationCommandOptionType} type The type of the option
|
|
155
|
+
* @property {boolean} [autocomplete] Whether the autocomplete interaction is enabled for a
|
|
156
|
+
* {@link ApplicationCommandOptionType.String}, {@link ApplicationCommandOptionType.Integer} or
|
|
157
|
+
* {@link ApplicationCommandOptionType.Number} option
|
|
158
|
+
* @property {string|number|boolean} [value] The value of the option
|
|
159
|
+
* @property {CommandInteractionOption[]} [options] Additional options if this option is a
|
|
160
|
+
* subcommand (group)
|
|
161
|
+
* @property {User} [user] The resolved user
|
|
162
|
+
* @property {GuildMember|APIGuildMember} [member] The resolved member
|
|
163
|
+
* @property {GuildChannel|ThreadChannel|APIChannel} [channel] The resolved channel
|
|
164
|
+
* @property {Role|APIRole} [role] The resolved role
|
|
165
|
+
* @property {Attachment} [attachment] The resolved attachment
|
|
166
|
+
*/
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Transforms an option received from the API.
|
|
170
|
+
* @param {APIApplicationCommandOption} option The received option
|
|
171
|
+
* @param {APIInteractionDataResolved} resolved The resolved interaction data
|
|
172
|
+
* @returns {CommandInteractionOption}
|
|
173
|
+
* @private
|
|
174
|
+
*/
|
|
175
|
+
transformOption(option, resolved) {
|
|
176
|
+
const result = {
|
|
177
|
+
name: option.name,
|
|
178
|
+
type: option.type,
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
if ('value' in option) result.value = option.value;
|
|
182
|
+
if ('options' in option) result.options = option.options.map(opt => this.transformOption(opt, resolved));
|
|
183
|
+
|
|
184
|
+
if (resolved) {
|
|
185
|
+
const user = resolved.users?.[option.value];
|
|
186
|
+
if (user) result.user = this.client.users._add(user);
|
|
187
|
+
|
|
188
|
+
const member = resolved.members?.[option.value];
|
|
189
|
+
if (member) result.member = this.guild?.members._add({ user, ...member }) ?? member;
|
|
190
|
+
|
|
191
|
+
const channel = resolved.channels?.[option.value];
|
|
192
|
+
if (channel) result.channel = this.client.channels._add(channel, this.guild) ?? channel;
|
|
193
|
+
|
|
194
|
+
const role = resolved.roles?.[option.value];
|
|
195
|
+
if (role) result.role = this.guild?.roles._add(role) ?? role;
|
|
196
|
+
|
|
197
|
+
const attachment = resolved.attachments?.[option.value];
|
|
198
|
+
if (attachment) result.attachment = new Attachment(attachment);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return result;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// These are here only for documentation purposes - they are implemented by InteractionResponses
|
|
205
|
+
/* eslint-disable no-empty-function */
|
|
206
|
+
deferReply() {}
|
|
207
|
+
reply() {}
|
|
208
|
+
fetchReply() {}
|
|
209
|
+
editReply() {}
|
|
210
|
+
deleteReply() {}
|
|
211
|
+
followUp() {}
|
|
212
|
+
showModal() {}
|
|
213
|
+
awaitModalSubmit() {}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
InteractionResponses.applyToClass(CommandInteraction, ['deferUpdate', 'update']);
|
|
217
|
+
|
|
218
|
+
module.exports = CommandInteraction;
|
|
219
|
+
|
|
220
|
+
/* eslint-disable max-len */
|
|
221
|
+
/**
|
|
222
|
+
* @external APIInteractionDataResolved
|
|
223
|
+
* @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-resolved-data-structure}
|
|
224
|
+
*/
|