discord-sb.js 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 +674 -0
- package/README.md +2 -0
- package/package.json +91 -0
- package/src/WebSocket.js +39 -0
- package/src/client/BaseClient.js +86 -0
- package/src/client/Client.js +978 -0
- package/src/client/WebhookClient.js +61 -0
- package/src/client/actions/Action.js +116 -0
- package/src/client/actions/ActionsManager.js +80 -0
- package/src/client/actions/ApplicationCommandPermissionsUpdate.js +34 -0
- package/src/client/actions/AutoModerationActionExecution.js +27 -0
- package/src/client/actions/AutoModerationRuleCreate.js +28 -0
- package/src/client/actions/AutoModerationRuleDelete.js +32 -0
- package/src/client/actions/AutoModerationRuleUpdate.js +30 -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/InviteCreate.js +28 -0
- package/src/client/actions/InviteDelete.js +30 -0
- package/src/client/actions/MessageCreate.js +50 -0
- package/src/client/actions/MessageDelete.js +32 -0
- package/src/client/actions/MessageDeleteBulk.js +46 -0
- package/src/client/actions/MessagePollVoteAdd.js +33 -0
- package/src/client/actions/MessagePollVoteRemove.js +33 -0
- package/src/client/actions/MessageReactionAdd.js +68 -0
- package/src/client/actions/MessageReactionRemove.js +50 -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 +50 -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 +50 -0
- package/src/client/actions/WebhooksUpdate.js +20 -0
- package/src/client/voice/ClientVoiceManager.js +151 -0
- package/src/client/voice/VoiceConnection.js +1249 -0
- package/src/client/voice/dispatcher/AnnexBDispatcher.js +120 -0
- package/src/client/voice/dispatcher/AudioDispatcher.js +145 -0
- package/src/client/voice/dispatcher/BaseDispatcher.js +459 -0
- package/src/client/voice/dispatcher/VPxDispatcher.js +54 -0
- package/src/client/voice/dispatcher/VideoDispatcher.js +68 -0
- package/src/client/voice/networking/VoiceUDPClient.js +173 -0
- package/src/client/voice/networking/VoiceWebSocket.js +286 -0
- package/src/client/voice/player/MediaPlayer.js +321 -0
- package/src/client/voice/player/processing/AnnexBNalSplitter.js +244 -0
- package/src/client/voice/player/processing/IvfSplitter.js +106 -0
- package/src/client/voice/player/processing/PCMInsertSilence.js +37 -0
- package/src/client/voice/receiver/PacketHandler.js +260 -0
- package/src/client/voice/receiver/Receiver.js +96 -0
- package/src/client/voice/receiver/Recorder.js +173 -0
- package/src/client/voice/util/Function.js +116 -0
- package/src/client/voice/util/PlayInterface.js +122 -0
- package/src/client/voice/util/Secretbox.js +64 -0
- package/src/client/voice/util/Silence.js +16 -0
- package/src/client/voice/util/Socket.js +62 -0
- package/src/client/voice/util/VolumeInterface.js +104 -0
- package/src/client/websocket/WebSocketManager.js +392 -0
- package/src/client/websocket/WebSocketShard.js +907 -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 +19 -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_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 +52 -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_MODAL_CREATE.js +12 -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_POLL_VOTE_ADD.js +5 -0
- package/src/client/websocket/handlers/MESSAGE_POLL_VOTE_REMOVE.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 +121 -0
- package/src/client/websocket/handlers/RELATIONSHIP_ADD.js +19 -0
- package/src/client/websocket/handlers/RELATIONSHIP_REMOVE.js +17 -0
- package/src/client/websocket/handlers/RELATIONSHIP_UPDATE.js +41 -0
- package/src/client/websocket/handlers/RESUMED.js +14 -0
- package/src/client/websocket/handlers/STAGE_INSTANCE_CREATE.js +5 -0
- package/src/client/websocket/handlers/STAGE_INSTANCE_DELETE.js +5 -0
- package/src/client/websocket/handlers/STAGE_INSTANCE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/THREAD_CREATE.js +5 -0
- package/src/client/websocket/handlers/THREAD_DELETE.js +5 -0
- package/src/client/websocket/handlers/THREAD_LIST_SYNC.js +5 -0
- package/src/client/websocket/handlers/THREAD_MEMBERS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/THREAD_MEMBER_UPDATE.js +5 -0
- package/src/client/websocket/handlers/THREAD_UPDATE.js +16 -0
- package/src/client/websocket/handlers/TYPING_START.js +5 -0
- package/src/client/websocket/handlers/USER_GUILD_SETTINGS_UPDATE.js +6 -0
- package/src/client/websocket/handlers/USER_NOTE_UPDATE.js +5 -0
- package/src/client/websocket/handlers/USER_REQUIRED_ACTION_UPDATE.js +78 -0
- package/src/client/websocket/handlers/USER_SETTINGS_UPDATE.js +5 -0
- package/src/client/websocket/handlers/USER_UPDATE.js +5 -0
- package/src/client/websocket/handlers/VOICE_CHANNEL_EFFECT_SEND.js +16 -0
- package/src/client/websocket/handlers/VOICE_CHANNEL_STATUS_UPDATE.js +12 -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 +84 -0
- package/src/errors/DJSError.js +61 -0
- package/src/errors/Messages.js +217 -0
- package/src/errors/index.js +4 -0
- package/src/index.js +172 -0
- package/src/managers/ApplicationCommandManager.js +264 -0
- package/src/managers/ApplicationCommandPermissionsManager.js +417 -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 +148 -0
- package/src/managers/ClientUserSettingManager.js +372 -0
- package/src/managers/DataManager.js +61 -0
- package/src/managers/DeveloperManager.js +254 -0
- package/src/managers/GuildBanManager.js +250 -0
- package/src/managers/GuildChannelManager.js +488 -0
- package/src/managers/GuildEmojiManager.js +171 -0
- package/src/managers/GuildEmojiRoleManager.js +118 -0
- package/src/managers/GuildForumThreadManager.js +108 -0
- package/src/managers/GuildInviteManager.js +213 -0
- package/src/managers/GuildManager.js +338 -0
- package/src/managers/GuildMemberManager.js +599 -0
- package/src/managers/GuildMemberRoleManager.js +195 -0
- package/src/managers/GuildScheduledEventManager.js +314 -0
- package/src/managers/GuildSettingManager.js +155 -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 +423 -0
- package/src/managers/PermissionOverwriteManager.js +164 -0
- package/src/managers/PresenceManager.js +71 -0
- package/src/managers/QuestManager.js +353 -0
- package/src/managers/ReactionManager.js +67 -0
- package/src/managers/ReactionUserManager.js +73 -0
- package/src/managers/RelationshipManager.js +278 -0
- package/src/managers/RoleManager.js +448 -0
- package/src/managers/SessionManager.js +66 -0
- package/src/managers/StageInstanceManager.js +162 -0
- package/src/managers/ThreadManager.js +175 -0
- package/src/managers/ThreadMemberManager.js +186 -0
- package/src/managers/UserManager.js +136 -0
- package/src/managers/UserNoteManager.js +53 -0
- package/src/managers/VoiceStateManager.js +59 -0
- package/src/rest/APIRequest.js +154 -0
- package/src/rest/APIRouter.js +53 -0
- package/src/rest/DiscordAPIError.js +119 -0
- package/src/rest/HTTPError.js +62 -0
- package/src/rest/RESTManager.js +67 -0
- package/src/rest/RateLimitError.js +55 -0
- package/src/rest/RequestHandler.js +466 -0
- package/src/sharding/Shard.js +444 -0
- package/src/sharding/ShardClientUtil.js +279 -0
- package/src/sharding/ShardingManager.js +319 -0
- package/src/structures/AnonymousGuild.js +98 -0
- package/src/structures/ApplicationCommand.js +593 -0
- package/src/structures/ApplicationRoleConnectionMetadata.js +48 -0
- package/src/structures/AutoModerationActionExecution.js +89 -0
- package/src/structures/AutoModerationRule.js +294 -0
- package/src/structures/AutocompleteInteraction.js +107 -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 +191 -0
- package/src/structures/BaseGuildVoiceChannel.js +241 -0
- package/src/structures/BaseMessageComponent.js +181 -0
- package/src/structures/ButtonInteraction.js +11 -0
- package/src/structures/CallState.js +63 -0
- package/src/structures/CategoryChannel.js +85 -0
- package/src/structures/Channel.js +284 -0
- package/src/structures/ClientPresence.js +77 -0
- package/src/structures/ClientUser.js +655 -0
- package/src/structures/CommandInteraction.js +41 -0
- package/src/structures/CommandInteractionOptionResolver.js +276 -0
- package/src/structures/ContainerComponent.js +68 -0
- package/src/structures/ContextMenuInteraction.js +65 -0
- package/src/structures/DMChannel.js +219 -0
- package/src/structures/DirectoryChannel.js +20 -0
- package/src/structures/Emoji.js +148 -0
- package/src/structures/FileComponent.js +49 -0
- package/src/structures/ForumChannel.js +31 -0
- package/src/structures/GroupDMChannel.js +394 -0
- package/src/structures/Guild.js +1791 -0
- package/src/structures/GuildAuditLogs.js +746 -0
- package/src/structures/GuildBan.js +59 -0
- package/src/structures/GuildBoost.js +108 -0
- package/src/structures/GuildChannel.js +470 -0
- package/src/structures/GuildEmoji.js +161 -0
- package/src/structures/GuildMember.js +636 -0
- package/src/structures/GuildPreview.js +191 -0
- package/src/structures/GuildPreviewEmoji.js +27 -0
- package/src/structures/GuildScheduledEvent.js +536 -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 +290 -0
- package/src/structures/InteractionCollector.js +248 -0
- package/src/structures/InteractionWebhook.js +43 -0
- package/src/structures/Invite.js +358 -0
- package/src/structures/InviteGuild.js +23 -0
- package/src/structures/InviteStageInstance.js +86 -0
- package/src/structures/MediaChannel.js +11 -0
- package/src/structures/MediaGalleryComponent.js +41 -0
- package/src/structures/MediaGalleryItem.js +47 -0
- package/src/structures/Message.js +1252 -0
- package/src/structures/MessageActionRow.js +105 -0
- package/src/structures/MessageAttachment.js +216 -0
- package/src/structures/MessageButton.js +166 -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 +596 -0
- package/src/structures/MessageMentions.js +273 -0
- package/src/structures/MessagePayload.js +354 -0
- package/src/structures/MessageReaction.js +181 -0
- package/src/structures/MessageSelectMenu.js +141 -0
- package/src/structures/Modal.js +161 -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/PermissionOverwrites.js +198 -0
- package/src/structures/Poll.js +108 -0
- package/src/structures/PollAnswer.js +88 -0
- package/src/structures/Presence.js +1157 -0
- package/src/structures/ReactionCollector.js +229 -0
- package/src/structures/ReactionEmoji.js +31 -0
- package/src/structures/Role.js +590 -0
- package/src/structures/SectionComponent.js +48 -0
- package/src/structures/SelectMenuInteraction.js +21 -0
- package/src/structures/SeparatorComponent.js +48 -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 +118 -0
- package/src/structures/TeamMember.js +80 -0
- package/src/structures/TextChannel.js +33 -0
- package/src/structures/TextDisplayComponent.js +40 -0
- package/src/structures/TextInputComponent.js +132 -0
- package/src/structures/ThreadChannel.js +605 -0
- package/src/structures/ThreadMember.js +105 -0
- package/src/structures/ThreadOnlyChannel.js +249 -0
- package/src/structures/ThumbnailComponent.js +57 -0
- package/src/structures/Typing.js +74 -0
- package/src/structures/UnfurledMediaItem.js +29 -0
- package/src/structures/User.js +640 -0
- package/src/structures/UserContextMenuInteraction.js +29 -0
- package/src/structures/VoiceChannel.js +110 -0
- package/src/structures/VoiceChannelEffect.js +69 -0
- package/src/structures/VoiceRegion.js +53 -0
- package/src/structures/VoiceState.js +354 -0
- package/src/structures/WebEmbed.js +373 -0
- package/src/structures/Webhook.js +478 -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 +953 -0
- package/src/structures/interfaces/Collector.js +300 -0
- package/src/structures/interfaces/InteractionResponses.js +313 -0
- package/src/structures/interfaces/TextBasedChannel.js +821 -0
- package/src/util/APITypes.js +59 -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 +1914 -0
- package/src/util/DataResolver.js +146 -0
- package/src/util/Formatters.js +228 -0
- package/src/util/GuildMemberFlags.js +43 -0
- package/src/util/Intents.js +74 -0
- package/src/util/InviteFlags.js +34 -0
- package/src/util/LimitedCollection.js +131 -0
- package/src/util/MessageFlags.js +63 -0
- package/src/util/Options.js +358 -0
- package/src/util/Permissions.js +202 -0
- package/src/util/PremiumUsageFlags.js +31 -0
- package/src/util/PurchasedFlags.js +33 -0
- package/src/util/RemoteAuth.js +415 -0
- package/src/util/RoleFlags.js +37 -0
- package/src/util/SnowflakeUtil.js +92 -0
- package/src/util/Speaking.js +33 -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 +1048 -0
- package/typings/enums.d.ts +439 -0
- package/typings/index.d.ts +8505 -0
- package/typings/index.test-d.ts +0 -0
- package/typings/rawDataTypes.d.ts +403 -0
|
@@ -0,0 +1,593 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Base = require('./Base');
|
|
4
|
+
const ApplicationCommandPermissionsManager = require('../managers/ApplicationCommandPermissionsManager');
|
|
5
|
+
const { ApplicationCommandOptionTypes, ApplicationCommandTypes, ChannelTypes } = require('../util/Constants');
|
|
6
|
+
const Permissions = require('../util/Permissions');
|
|
7
|
+
const SnowflakeUtil = require('../util/SnowflakeUtil');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Represents an application command.
|
|
11
|
+
* @extends {Base}
|
|
12
|
+
*/
|
|
13
|
+
class ApplicationCommand extends Base {
|
|
14
|
+
constructor(client, data, guild, guildId) {
|
|
15
|
+
super(client);
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The command's id
|
|
19
|
+
* @type {Snowflake}
|
|
20
|
+
*/
|
|
21
|
+
this.id = data.id;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The parent application's id
|
|
25
|
+
* @type {Snowflake}
|
|
26
|
+
*/
|
|
27
|
+
this.applicationId = data.application_id;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The guild this command is part of
|
|
31
|
+
* @type {?Guild}
|
|
32
|
+
*/
|
|
33
|
+
this.guild = guild ?? null;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The guild's id this command is part of, this may be non-null when `guild` is `null` if the command
|
|
37
|
+
* was fetched from the `ApplicationCommandManager`
|
|
38
|
+
* @type {?Snowflake}
|
|
39
|
+
*/
|
|
40
|
+
this.guildId = guild?.id ?? guildId ?? null;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The manager for permissions of this command on its guild or arbitrary guilds when the command is global
|
|
44
|
+
* @type {ApplicationCommandPermissionsManager}
|
|
45
|
+
*/
|
|
46
|
+
this.permissions = new ApplicationCommandPermissionsManager(this);
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The type of this application command
|
|
50
|
+
* @type {ApplicationCommandType}
|
|
51
|
+
*/
|
|
52
|
+
this.type = ApplicationCommandTypes[data.type];
|
|
53
|
+
|
|
54
|
+
this._patch(data);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
_patch(data) {
|
|
58
|
+
if ('name' in data) {
|
|
59
|
+
/**
|
|
60
|
+
* The name of this command
|
|
61
|
+
* @type {string}
|
|
62
|
+
*/
|
|
63
|
+
this.name = data.name;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if ('name_localizations' in data) {
|
|
67
|
+
/**
|
|
68
|
+
* The name localizations for this command
|
|
69
|
+
* @type {?Object<Locale, string>}
|
|
70
|
+
*/
|
|
71
|
+
this.nameLocalizations = data.name_localizations;
|
|
72
|
+
} else {
|
|
73
|
+
this.nameLocalizations ??= null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if ('name_localized' in data) {
|
|
77
|
+
/**
|
|
78
|
+
* The localized name for this command
|
|
79
|
+
* @type {?string}
|
|
80
|
+
*/
|
|
81
|
+
this.nameLocalized = data.name_localized;
|
|
82
|
+
} else {
|
|
83
|
+
this.nameLocalized ??= null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if ('description' in data) {
|
|
87
|
+
/**
|
|
88
|
+
* The description of this command
|
|
89
|
+
* @type {string}
|
|
90
|
+
*/
|
|
91
|
+
this.description = data.description;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if ('description_localizations' in data) {
|
|
95
|
+
/**
|
|
96
|
+
* The description localizations for this command
|
|
97
|
+
* @type {?Object<Locale, string>}
|
|
98
|
+
*/
|
|
99
|
+
this.descriptionLocalizations = data.description_localizations;
|
|
100
|
+
} else {
|
|
101
|
+
this.descriptionLocalizations ??= null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if ('description_localized' in data) {
|
|
105
|
+
/**
|
|
106
|
+
* The localized description for this command
|
|
107
|
+
* @type {?string}
|
|
108
|
+
*/
|
|
109
|
+
this.descriptionLocalized = data.description_localized;
|
|
110
|
+
} else {
|
|
111
|
+
this.descriptionLocalized ??= null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if ('options' in data) {
|
|
115
|
+
/**
|
|
116
|
+
* The options of this command
|
|
117
|
+
* @type {ApplicationCommandOption[]}
|
|
118
|
+
*/
|
|
119
|
+
this.options = data.options.map(o => this.constructor.transformOption(o, true));
|
|
120
|
+
} else {
|
|
121
|
+
this.options ??= [];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/* eslint-disable max-len */
|
|
125
|
+
if ('default_permission' in data) {
|
|
126
|
+
/**
|
|
127
|
+
* Whether the command is enabled by default when the app is added to a guild
|
|
128
|
+
* @type {boolean}
|
|
129
|
+
* @deprecated Use {@link ApplicationCommand.defaultMemberPermissions} and {@link ApplicationCommand.dmPermission} instead.
|
|
130
|
+
*/
|
|
131
|
+
this.defaultPermission = data.default_permission;
|
|
132
|
+
}
|
|
133
|
+
/* eslint-disable max-len */
|
|
134
|
+
|
|
135
|
+
if ('default_member_permissions' in data) {
|
|
136
|
+
/**
|
|
137
|
+
* The default bitfield used to determine whether this command be used in a guild
|
|
138
|
+
* @type {?Readonly<Permissions>}
|
|
139
|
+
*/
|
|
140
|
+
this.defaultMemberPermissions = data.default_member_permissions
|
|
141
|
+
? new Permissions(BigInt(data.default_member_permissions)).freeze()
|
|
142
|
+
: null;
|
|
143
|
+
} else {
|
|
144
|
+
this.defaultMemberPermissions ??= null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if ('dm_permission' in data) {
|
|
148
|
+
/**
|
|
149
|
+
* Whether the command can be used in DMs
|
|
150
|
+
* <info>This property is always `null` on guild commands</info>
|
|
151
|
+
* @type {?boolean}
|
|
152
|
+
*/
|
|
153
|
+
this.dmPermission = data.dm_permission;
|
|
154
|
+
} else {
|
|
155
|
+
this.dmPermission ??= null;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if ('version' in data) {
|
|
159
|
+
/**
|
|
160
|
+
* Autoincrementing version identifier updated during substantial record changes
|
|
161
|
+
* @type {Snowflake}
|
|
162
|
+
*/
|
|
163
|
+
this.version = data.version;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* The timestamp the command was created at
|
|
169
|
+
* @type {number}
|
|
170
|
+
* @readonly
|
|
171
|
+
*/
|
|
172
|
+
get createdTimestamp() {
|
|
173
|
+
return SnowflakeUtil.timestampFrom(this.id);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* The time the command was created at
|
|
178
|
+
* @type {Date}
|
|
179
|
+
* @readonly
|
|
180
|
+
*/
|
|
181
|
+
get createdAt() {
|
|
182
|
+
return new Date(this.createdTimestamp);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* The manager that this command belongs to
|
|
187
|
+
* @type {ApplicationCommandManager}
|
|
188
|
+
* @readonly
|
|
189
|
+
*/
|
|
190
|
+
get manager() {
|
|
191
|
+
return (this.guild ?? this.client.application).commands;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Data for creating or editing an application command.
|
|
196
|
+
* @typedef {Object} ApplicationCommandData
|
|
197
|
+
* @property {string} name The name of the command
|
|
198
|
+
* @property {Object<Locale, string>} [nameLocalizations] The localizations for the command name
|
|
199
|
+
* @property {string} description The description of the command
|
|
200
|
+
* @property {Object<Locale, string>} [descriptionLocalizations] The localizations for the command description
|
|
201
|
+
* @property {ApplicationCommandType} [type] The type of the command
|
|
202
|
+
* @property {ApplicationCommandOptionData[]} [options] Options for the command
|
|
203
|
+
* @property {boolean} [defaultPermission] Whether the command is enabled by default when the app is added to a guild
|
|
204
|
+
* @property {?PermissionResolvable} [defaultMemberPermissions] The bitfield used to determine the default permissions
|
|
205
|
+
* a member needs in order to run the command
|
|
206
|
+
* @property {boolean} [dmPermission] Whether the command is enabled in DMs
|
|
207
|
+
*/
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* An option for an application command or subcommand.
|
|
211
|
+
* <info>In addition to the listed properties, when used as a parameter,
|
|
212
|
+
* API style `snake_case` properties can be used for compatibility with generators like `@discordjs/builders`.</info>
|
|
213
|
+
* <warn>Note that providing a value for the `camelCase` counterpart for any `snake_case` property
|
|
214
|
+
* will discard the provided `snake_case` property.</warn>
|
|
215
|
+
* @typedef {Object} ApplicationCommandOptionData
|
|
216
|
+
* @property {ApplicationCommandOptionType|number} type The type of the option
|
|
217
|
+
* @property {string} name The name of the option
|
|
218
|
+
* @property {Object<Locale, string>} [nameLocalizations] The name localizations for the option
|
|
219
|
+
* @property {string} description The description of the option
|
|
220
|
+
* @property {Object<Locale, string>} [descriptionLocalizations] The description localizations for the option
|
|
221
|
+
* @property {boolean} [autocomplete] Whether the option is an autocomplete option
|
|
222
|
+
* @property {boolean} [required] Whether the option is required
|
|
223
|
+
* @property {ApplicationCommandOptionChoiceData[]} [choices] The choices of the option for the user to pick from
|
|
224
|
+
* @property {ApplicationCommandOptionData[]} [options] Additional options if this option is a subcommand (group)
|
|
225
|
+
* @property {ChannelType[]|number[]} [channelTypes] When the option type is channel,
|
|
226
|
+
* the allowed types of channels that can be selected
|
|
227
|
+
* @property {number} [minValue] The minimum value for an `INTEGER` or `NUMBER` option
|
|
228
|
+
* @property {number} [maxValue] The maximum value for an `INTEGER` or `NUMBER` option
|
|
229
|
+
* @property {number} [minLength] The minimum length for a `STRING` option
|
|
230
|
+
* (maximum of `6000`)
|
|
231
|
+
* @property {number} [maxLength] The maximum length for a `STRING` option
|
|
232
|
+
* (maximum of `6000`)
|
|
233
|
+
*/
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* @typedef {Object} ApplicationCommandOptionChoiceData
|
|
237
|
+
* @property {string} name The name of the choice
|
|
238
|
+
* @property {Object<Locale, string>} [nameLocalizations] The localized names for this choice
|
|
239
|
+
* @property {string|number} value The value of the choice
|
|
240
|
+
*/
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Edits this application command.
|
|
244
|
+
* @param {Partial<ApplicationCommandData>} data The data to update the command with
|
|
245
|
+
* @returns {Promise<ApplicationCommand>}
|
|
246
|
+
* @example
|
|
247
|
+
* // Edit the description of this command
|
|
248
|
+
* command.edit({
|
|
249
|
+
* description: 'New description',
|
|
250
|
+
* })
|
|
251
|
+
* .then(console.log)
|
|
252
|
+
* .catch(console.error);
|
|
253
|
+
*/
|
|
254
|
+
edit(data) {
|
|
255
|
+
return this.manager.edit(this, data, this.guildId);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Edits the name of this ApplicationCommand
|
|
260
|
+
* @param {string} name The new name of the command
|
|
261
|
+
* @returns {Promise<ApplicationCommand>}
|
|
262
|
+
*/
|
|
263
|
+
setName(name) {
|
|
264
|
+
return this.edit({ name });
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Edits the localized names of this ApplicationCommand
|
|
269
|
+
* @param {Object<Locale, string>} nameLocalizations The new localized names for the command
|
|
270
|
+
* @returns {Promise<ApplicationCommand>}
|
|
271
|
+
* @example
|
|
272
|
+
* // Edit the name localizations of this command
|
|
273
|
+
* command.setLocalizedNames({
|
|
274
|
+
* 'en-GB': 'test',
|
|
275
|
+
* 'pt-BR': 'teste',
|
|
276
|
+
* })
|
|
277
|
+
* .then(console.log)
|
|
278
|
+
* .catch(console.error)
|
|
279
|
+
*/
|
|
280
|
+
setNameLocalizations(nameLocalizations) {
|
|
281
|
+
return this.edit({ nameLocalizations });
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Edits the description of this ApplicationCommand
|
|
286
|
+
* @param {string} description The new description of the command
|
|
287
|
+
* @returns {Promise<ApplicationCommand>}
|
|
288
|
+
*/
|
|
289
|
+
setDescription(description) {
|
|
290
|
+
return this.edit({ description });
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Edits the localized descriptions of this ApplicationCommand
|
|
295
|
+
* @param {Object<Locale, string>} descriptionLocalizations The new localized descriptions for the command
|
|
296
|
+
* @returns {Promise<ApplicationCommand>}
|
|
297
|
+
* @example
|
|
298
|
+
* // Edit the description localizations of this command
|
|
299
|
+
* command.setLocalizedDescriptions({
|
|
300
|
+
* 'en-GB': 'A test command',
|
|
301
|
+
* 'pt-BR': 'Um comando de teste',
|
|
302
|
+
* })
|
|
303
|
+
* .then(console.log)
|
|
304
|
+
* .catch(console.error)
|
|
305
|
+
*/
|
|
306
|
+
setDescriptionLocalizations(descriptionLocalizations) {
|
|
307
|
+
return this.edit({ descriptionLocalizations });
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/* eslint-disable max-len */
|
|
311
|
+
/**
|
|
312
|
+
* Edits the default permission of this ApplicationCommand
|
|
313
|
+
* @param {boolean} [defaultPermission=true] The default permission for this command
|
|
314
|
+
* @returns {Promise<ApplicationCommand>}
|
|
315
|
+
* @deprecated Use {@link ApplicationCommand#setDefaultMemberPermissions} and {@link ApplicationCommand#setDMPermission} instead.
|
|
316
|
+
*/
|
|
317
|
+
setDefaultPermission(defaultPermission = true) {
|
|
318
|
+
return this.edit({ defaultPermission });
|
|
319
|
+
}
|
|
320
|
+
/* eslint-enable max-len */
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Edits the default member permissions of this ApplicationCommand
|
|
324
|
+
* @param {?PermissionResolvable} defaultMemberPermissions The default member permissions required to run this command
|
|
325
|
+
* @returns {Promise<ApplicationCommand>}
|
|
326
|
+
*/
|
|
327
|
+
setDefaultMemberPermissions(defaultMemberPermissions) {
|
|
328
|
+
return this.edit({ defaultMemberPermissions });
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Edits the DM permission of this ApplicationCommand
|
|
333
|
+
* @param {boolean} [dmPermission=true] Whether the command can be used in DMs
|
|
334
|
+
* @returns {Promise<ApplicationCommand>}
|
|
335
|
+
*/
|
|
336
|
+
setDMPermission(dmPermission = true) {
|
|
337
|
+
return this.edit({ dmPermission });
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Edits the options of this ApplicationCommand
|
|
342
|
+
* @param {ApplicationCommandOptionData[]} options The options to set for this command
|
|
343
|
+
* @returns {Promise<ApplicationCommand>}
|
|
344
|
+
*/
|
|
345
|
+
setOptions(options) {
|
|
346
|
+
return this.edit({ options });
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Deletes this command.
|
|
351
|
+
* @returns {Promise<ApplicationCommand>}
|
|
352
|
+
* @example
|
|
353
|
+
* // Delete this command
|
|
354
|
+
* command.delete()
|
|
355
|
+
* .then(console.log)
|
|
356
|
+
* .catch(console.error);
|
|
357
|
+
*/
|
|
358
|
+
delete() {
|
|
359
|
+
return this.manager.delete(this, this.guildId);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Whether this command equals another command. It compares all properties, so for most operations
|
|
364
|
+
* it is advisable to just compare `command.id === command2.id` as it is much faster and is often
|
|
365
|
+
* what most users need.
|
|
366
|
+
* @param {ApplicationCommand|ApplicationCommandData|APIApplicationCommand} command The command to compare with
|
|
367
|
+
* @param {boolean} [enforceOptionOrder=false] Whether to strictly check that options and choices are in the same
|
|
368
|
+
* order in the array <info>The client may not always respect this ordering!</info>
|
|
369
|
+
* @returns {boolean}
|
|
370
|
+
*/
|
|
371
|
+
equals(command, enforceOptionOrder = false) {
|
|
372
|
+
// If given an id, check if the id matches
|
|
373
|
+
if (command.id && this.id !== command.id) return false;
|
|
374
|
+
|
|
375
|
+
let defaultMemberPermissions = null;
|
|
376
|
+
let dmPermission = command.dmPermission ?? command.dm_permission;
|
|
377
|
+
|
|
378
|
+
if ('default_member_permissions' in command) {
|
|
379
|
+
defaultMemberPermissions = command.default_member_permissions
|
|
380
|
+
? new Permissions(BigInt(command.default_member_permissions)).bitfield
|
|
381
|
+
: null;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
if ('defaultMemberPermissions' in command) {
|
|
385
|
+
defaultMemberPermissions =
|
|
386
|
+
command.defaultMemberPermissions !== null ? new Permissions(command.defaultMemberPermissions).bitfield : null;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// Check top level parameters
|
|
390
|
+
const commandType = typeof command.type === 'string' ? command.type : ApplicationCommandTypes[command.type];
|
|
391
|
+
if (
|
|
392
|
+
command.name !== this.name ||
|
|
393
|
+
('description' in command && command.description !== this.description) ||
|
|
394
|
+
('version' in command && command.version !== this.version) ||
|
|
395
|
+
('autocomplete' in command && command.autocomplete !== this.autocomplete) ||
|
|
396
|
+
(commandType && commandType !== this.type) ||
|
|
397
|
+
defaultMemberPermissions !== (this.defaultMemberPermissions?.bitfield ?? null) ||
|
|
398
|
+
(typeof dmPermission !== 'undefined' && dmPermission !== this.dmPermission) ||
|
|
399
|
+
// Future proof for options being nullable
|
|
400
|
+
// TODO: remove ?? 0 on each when nullable
|
|
401
|
+
(command.options?.length ?? 0) !== (this.options?.length ?? 0) ||
|
|
402
|
+
(command.defaultPermission ?? command.default_permission ?? true) !== this.defaultPermission
|
|
403
|
+
) {
|
|
404
|
+
return false;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
if (command.options) {
|
|
408
|
+
return this.constructor.optionsEqual(this.options, command.options, enforceOptionOrder);
|
|
409
|
+
}
|
|
410
|
+
return true;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Recursively checks that all options for an {@link ApplicationCommand} are equal to the provided options.
|
|
415
|
+
* In most cases it is better to compare using {@link ApplicationCommand#equals}
|
|
416
|
+
* @param {ApplicationCommandOptionData[]} existing The options on the existing command,
|
|
417
|
+
* should be {@link ApplicationCommand#options}
|
|
418
|
+
* @param {ApplicationCommandOptionData[]|APIApplicationCommandOption[]} options The options to compare against
|
|
419
|
+
* @param {boolean} [enforceOptionOrder=false] Whether to strictly check that options and choices are in the same
|
|
420
|
+
* order in the array <info>The client may not always respect this ordering!</info>
|
|
421
|
+
* @returns {boolean}
|
|
422
|
+
*/
|
|
423
|
+
static optionsEqual(existing, options, enforceOptionOrder = false) {
|
|
424
|
+
if (existing.length !== options.length) return false;
|
|
425
|
+
if (enforceOptionOrder) {
|
|
426
|
+
return existing.every((option, index) => this._optionEquals(option, options[index], enforceOptionOrder));
|
|
427
|
+
}
|
|
428
|
+
const newOptions = new Map(options.map(option => [option.name, option]));
|
|
429
|
+
for (const option of existing) {
|
|
430
|
+
const foundOption = newOptions.get(option.name);
|
|
431
|
+
if (!foundOption || !this._optionEquals(option, foundOption)) return false;
|
|
432
|
+
}
|
|
433
|
+
return true;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Checks that an option for an {@link ApplicationCommand} is equal to the provided option
|
|
438
|
+
* In most cases it is better to compare using {@link ApplicationCommand#equals}
|
|
439
|
+
* @param {ApplicationCommandOptionData} existing The option on the existing command,
|
|
440
|
+
* should be from {@link ApplicationCommand#options}
|
|
441
|
+
* @param {ApplicationCommandOptionData|APIApplicationCommandOption} option The option to compare against
|
|
442
|
+
* @param {boolean} [enforceOptionOrder=false] Whether to strictly check that options or choices are in the same
|
|
443
|
+
* order in their array <info>The client may not always respect this ordering!</info>
|
|
444
|
+
* @returns {boolean}
|
|
445
|
+
* @private
|
|
446
|
+
*/
|
|
447
|
+
static _optionEquals(existing, option, enforceOptionOrder = false) {
|
|
448
|
+
const optionType = typeof option.type === 'string' ? option.type : ApplicationCommandOptionTypes[option.type];
|
|
449
|
+
if (
|
|
450
|
+
option.name !== existing.name ||
|
|
451
|
+
optionType !== existing.type ||
|
|
452
|
+
option.description !== existing.description ||
|
|
453
|
+
option.autocomplete !== existing.autocomplete ||
|
|
454
|
+
(option.required ?? (['SUB_COMMAND', 'SUB_COMMAND_GROUP'].includes(optionType) ? undefined : false)) !==
|
|
455
|
+
existing.required ||
|
|
456
|
+
option.choices?.length !== existing.choices?.length ||
|
|
457
|
+
option.options?.length !== existing.options?.length ||
|
|
458
|
+
(option.channelTypes ?? option.channel_types)?.length !== existing.channelTypes?.length ||
|
|
459
|
+
(option.minValue ?? option.min_value) !== existing.minValue ||
|
|
460
|
+
(option.maxValue ?? option.max_value) !== existing.maxValue ||
|
|
461
|
+
(option.minLength ?? option.min_length) !== existing.minLength ||
|
|
462
|
+
(option.maxLength ?? option.max_length) !== existing.maxLength
|
|
463
|
+
) {
|
|
464
|
+
return false;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
if (existing.choices) {
|
|
468
|
+
if (
|
|
469
|
+
enforceOptionOrder &&
|
|
470
|
+
!existing.choices.every(
|
|
471
|
+
(choice, index) => choice.name === option.choices[index].name && choice.value === option.choices[index].value,
|
|
472
|
+
)
|
|
473
|
+
) {
|
|
474
|
+
return false;
|
|
475
|
+
}
|
|
476
|
+
if (!enforceOptionOrder) {
|
|
477
|
+
const newChoices = new Map(option.choices.map(choice => [choice.name, choice]));
|
|
478
|
+
for (const choice of existing.choices) {
|
|
479
|
+
const foundChoice = newChoices.get(choice.name);
|
|
480
|
+
if (!foundChoice || foundChoice.value !== choice.value) return false;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
if (existing.channelTypes) {
|
|
486
|
+
const newTypes = (option.channelTypes ?? option.channel_types).map(type =>
|
|
487
|
+
typeof type === 'number' ? ChannelTypes[type] : type,
|
|
488
|
+
);
|
|
489
|
+
for (const type of existing.channelTypes) {
|
|
490
|
+
if (!newTypes.includes(type)) return false;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
if (existing.options) {
|
|
495
|
+
return this.optionsEqual(existing.options, option.options, enforceOptionOrder);
|
|
496
|
+
}
|
|
497
|
+
return true;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* An option for an application command or subcommand.
|
|
502
|
+
* @typedef {Object} ApplicationCommandOption
|
|
503
|
+
* @property {ApplicationCommandOptionType} type The type of the option
|
|
504
|
+
* @property {string} name The name of the option
|
|
505
|
+
* @property {Object<string, string>} [nameLocalizations] The localizations for the option name
|
|
506
|
+
* @property {string} [nameLocalized] The localized name for this option
|
|
507
|
+
* @property {string} description The description of the option
|
|
508
|
+
* @property {Object<string, string>} [descriptionLocalizations] The localizations for the option description
|
|
509
|
+
* @property {string} [descriptionLocalized] The localized description for this option
|
|
510
|
+
* @property {boolean} [required] Whether the option is required
|
|
511
|
+
* @property {boolean} [autocomplete] Whether the option is an autocomplete option
|
|
512
|
+
* @property {ApplicationCommandOptionChoice[]} [choices] The choices of the option for the user to pick from
|
|
513
|
+
* @property {ApplicationCommandOption[]} [options] Additional options if this option is a subcommand (group)
|
|
514
|
+
* @property {ChannelType[]} [channelTypes] When the option type is channel,
|
|
515
|
+
* the allowed types of channels that can be selected
|
|
516
|
+
* @property {number} [minValue] The minimum value for an `INTEGER` or `NUMBER` option
|
|
517
|
+
* @property {number} [maxValue] The maximum value for an `INTEGER` or `NUMBER` option
|
|
518
|
+
* @property {number} [minLength] The minimum length for a `STRING` option
|
|
519
|
+
* (maximum of `6000`)
|
|
520
|
+
* @property {number} [maxLength] The maximum length for a `STRING` option
|
|
521
|
+
* (maximum of `6000`)
|
|
522
|
+
*/
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* A choice for an application command option.
|
|
526
|
+
* @typedef {Object} ApplicationCommandOptionChoice
|
|
527
|
+
* @property {string} name The name of the choice
|
|
528
|
+
* @property {?string} nameLocalized The localized name of the choice in the provided locale, if any
|
|
529
|
+
* @property {?Object<string, string>} [nameLocalizations] The localized names for this choice
|
|
530
|
+
* @property {string|number} value The value of the choice
|
|
531
|
+
*/
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* Transforms an {@link ApplicationCommandOptionData} object into something that can be used with the API.
|
|
535
|
+
* @param {ApplicationCommandOptionData|ApplicationCommandOption} option The option to transform
|
|
536
|
+
* @param {boolean} [received] Whether this option has been received from Discord
|
|
537
|
+
* @returns {APIApplicationCommandOption}
|
|
538
|
+
* @private
|
|
539
|
+
*/
|
|
540
|
+
static transformOption(option, received) {
|
|
541
|
+
const stringType = typeof option.type === 'string' ? option.type : ApplicationCommandOptionTypes[option.type];
|
|
542
|
+
const channelTypesKey = received ? 'channelTypes' : 'channel_types';
|
|
543
|
+
const minValueKey = received ? 'minValue' : 'min_value';
|
|
544
|
+
const maxValueKey = received ? 'maxValue' : 'max_value';
|
|
545
|
+
const minLengthKey = received ? 'minLength' : 'min_length';
|
|
546
|
+
const maxLengthKey = received ? 'maxLength' : 'max_length';
|
|
547
|
+
const nameLocalizationsKey = received ? 'nameLocalizations' : 'name_localizations';
|
|
548
|
+
const nameLocalizedKey = received ? 'nameLocalized' : 'name_localized';
|
|
549
|
+
const descriptionLocalizationsKey = received ? 'descriptionLocalizations' : 'description_localizations';
|
|
550
|
+
const descriptionLocalizedKey = received ? 'descriptionLocalized' : 'description_localized';
|
|
551
|
+
return {
|
|
552
|
+
type: typeof option.type === 'number' && !received ? option.type : ApplicationCommandOptionTypes[option.type],
|
|
553
|
+
name: option.name,
|
|
554
|
+
[nameLocalizationsKey]: option.nameLocalizations ?? option.name_localizations,
|
|
555
|
+
[nameLocalizedKey]: option.nameLocalized ?? option.name_localized,
|
|
556
|
+
description: option.description,
|
|
557
|
+
[descriptionLocalizationsKey]: option.descriptionLocalizations ?? option.description_localizations,
|
|
558
|
+
[descriptionLocalizedKey]: option.descriptionLocalized ?? option.description_localized,
|
|
559
|
+
required:
|
|
560
|
+
option.required ?? (stringType === 'SUB_COMMAND' || stringType === 'SUB_COMMAND_GROUP' ? undefined : false),
|
|
561
|
+
autocomplete: option.autocomplete,
|
|
562
|
+
choices: option.choices?.map(choice => ({
|
|
563
|
+
name: choice.name,
|
|
564
|
+
[nameLocalizedKey]: choice.nameLocalized ?? choice.name_localized,
|
|
565
|
+
[nameLocalizationsKey]: choice.nameLocalizations ?? choice.name_localizations,
|
|
566
|
+
value: choice.value,
|
|
567
|
+
})),
|
|
568
|
+
options: option.options?.map(o => this.transformOption(o, received)),
|
|
569
|
+
[channelTypesKey]: received
|
|
570
|
+
? option.channel_types?.map(type => ChannelTypes[type])
|
|
571
|
+
: option.channelTypes?.map(type => (typeof type === 'string' ? ChannelTypes[type] : type)) ??
|
|
572
|
+
// When transforming to API data, accept API data
|
|
573
|
+
option.channel_types,
|
|
574
|
+
[minValueKey]: option.minValue ?? option.min_value,
|
|
575
|
+
[maxValueKey]: option.maxValue ?? option.max_value,
|
|
576
|
+
[minLengthKey]: option.minLength ?? option.min_length,
|
|
577
|
+
[maxLengthKey]: option.maxLength ?? option.max_length,
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
module.exports = ApplicationCommand;
|
|
583
|
+
|
|
584
|
+
/* eslint-disable max-len */
|
|
585
|
+
/**
|
|
586
|
+
* @external APIApplicationCommand
|
|
587
|
+
* @see {@link https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-structure}
|
|
588
|
+
*/
|
|
589
|
+
|
|
590
|
+
/**
|
|
591
|
+
* @external APIApplicationCommandOption
|
|
592
|
+
* @see {@link https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-structure}
|
|
593
|
+
*/
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { ApplicationRoleConnectionMetadataTypes } = require('../util/Constants');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Role connection metadata object for an application.
|
|
7
|
+
*/
|
|
8
|
+
class ApplicationRoleConnectionMetadata {
|
|
9
|
+
constructor(data) {
|
|
10
|
+
/**
|
|
11
|
+
* The name of this metadata field
|
|
12
|
+
* @type {string}
|
|
13
|
+
*/
|
|
14
|
+
this.name = data.name;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The name localizations for this metadata field
|
|
18
|
+
* @type {?Object<Locale, string>}
|
|
19
|
+
*/
|
|
20
|
+
this.nameLocalizations = data.name_localizations ?? null;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The description of this metadata field
|
|
24
|
+
* @type {string}
|
|
25
|
+
*/
|
|
26
|
+
this.description = data.description;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The description localizations for this metadata field
|
|
30
|
+
* @type {?Object<Locale, string>}
|
|
31
|
+
*/
|
|
32
|
+
this.descriptionLocalizations = data.description_localizations ?? null;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The dictionary key for this metadata field
|
|
36
|
+
* @type {string}
|
|
37
|
+
*/
|
|
38
|
+
this.key = data.key;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The type of this metadata field
|
|
42
|
+
* @type {ApplicationRoleConnectionMetadataType}
|
|
43
|
+
*/
|
|
44
|
+
this.type = typeof data.type === 'number' ? ApplicationRoleConnectionMetadataTypes[data.type] : data.type;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
exports.ApplicationRoleConnectionMetadata = ApplicationRoleConnectionMetadata;
|