lolka.js 0.1.4 → 0.2.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/README.md +6 -6
- package/package.json +21 -52
- package/src/client/BaseClient.js +120 -0
- package/src/client/Client.js +147 -446
- package/src/client/WebhookClient.js +103 -0
- package/src/client/actions/Action.js +3 -4
- package/src/client/actions/ActionsManager.js +65 -55
- 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 +3 -5
- package/src/client/actions/ChannelDelete.js +3 -4
- package/src/client/actions/ChannelUpdate.js +3 -3
- package/src/client/actions/EntitlementCreate.js +23 -0
- package/src/client/actions/EntitlementDelete.js +27 -0
- package/src/client/actions/EntitlementUpdate.js +25 -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 +3 -3
- package/src/client/actions/GuildDelete.js +44 -0
- package/src/client/actions/GuildEmojiCreate.js +3 -4
- package/src/client/actions/GuildEmojiDelete.js +3 -4
- package/src/client/actions/GuildEmojiUpdate.js +3 -4
- package/src/client/actions/GuildEmojisUpdate.js +2 -2
- package/src/client/actions/GuildIntegrationsUpdate.js +19 -0
- package/src/client/actions/GuildMemberRemove.js +6 -8
- package/src/client/actions/GuildMemberUpdate.js +6 -7
- package/src/client/actions/GuildRoleCreate.js +4 -6
- package/src/client/actions/GuildRoleDelete.js +3 -4
- package/src/client/actions/GuildRoleUpdate.js +39 -0
- package/src/client/actions/GuildRolesPositionUpdate.js +3 -3
- package/src/client/actions/GuildScheduledEventCreate.js +27 -0
- package/src/client/actions/GuildScheduledEventDelete.js +3 -4
- package/src/client/actions/GuildScheduledEventUpdate.js +30 -0
- package/src/client/actions/GuildScheduledEventUserAdd.js +3 -4
- package/src/client/actions/GuildScheduledEventUserRemove.js +3 -4
- package/src/client/actions/GuildSoundboardSoundDelete.js +3 -4
- package/src/client/actions/GuildStickerCreate.js +3 -4
- package/src/client/actions/GuildStickerDelete.js +3 -4
- package/src/client/actions/GuildStickerUpdate.js +3 -4
- package/src/client/actions/GuildStickersUpdate.js +2 -2
- package/src/client/actions/GuildUpdate.js +3 -4
- package/src/client/actions/InteractionCreate.js +15 -18
- package/src/client/actions/InviteCreate.js +27 -0
- package/src/client/actions/InviteDelete.js +29 -0
- package/src/client/actions/MessageCreate.js +3 -4
- package/src/client/actions/MessageDelete.js +3 -4
- package/src/client/actions/MessageDeleteBulk.js +3 -5
- package/src/client/actions/MessagePollVoteAdd.js +3 -4
- package/src/client/actions/MessagePollVoteRemove.js +3 -4
- package/src/client/actions/MessageReactionAdd.js +5 -7
- package/src/client/actions/MessageReactionRemove.js +4 -5
- package/src/client/actions/MessageReactionRemoveAll.js +4 -5
- package/src/client/actions/MessageReactionRemoveEmoji.js +4 -5
- package/src/client/actions/MessageUpdate.js +2 -2
- package/src/client/actions/PresenceUpdate.js +45 -0
- package/src/client/actions/StageInstanceCreate.js +3 -4
- package/src/client/actions/StageInstanceDelete.js +3 -4
- package/src/client/actions/StageInstanceUpdate.js +3 -4
- package/src/client/actions/ThreadCreate.js +3 -5
- 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 +3 -5
- package/src/client/actions/TypingStart.js +5 -6
- package/src/client/actions/UserUpdate.js +3 -4
- package/src/client/actions/VoiceStateUpdate.js +43 -0
- package/src/client/actions/WebhooksUpdate.js +37 -0
- package/src/client/voice/ClientVoiceManager.js +6 -10
- package/src/client/websocket/WebSocketManager.js +407 -0
- package/src/client/websocket/WebSocketShard.js +234 -0
- package/src/client/websocket/handlers/APPLICATION_COMMAND_PERMISSIONS_UPDATE.js +2 -27
- package/src/client/websocket/handlers/AUTO_MODERATION_ACTION_EXECUTION.js +2 -15
- package/src/client/websocket/handlers/AUTO_MODERATION_RULE_CREATE.js +2 -16
- package/src/client/websocket/handlers/AUTO_MODERATION_RULE_DELETE.js +2 -19
- package/src/client/websocket/handlers/AUTO_MODERATION_RULE_UPDATE.js +2 -18
- package/src/client/websocket/handlers/CHANNEL_PINS_UPDATE.js +1 -2
- package/src/client/websocket/handlers/CHANNEL_UPDATE.js +1 -2
- package/src/client/websocket/handlers/ENTITLEMENT_CREATE.js +2 -12
- package/src/client/websocket/handlers/ENTITLEMENT_DELETE.js +2 -16
- package/src/client/websocket/handlers/ENTITLEMENT_UPDATE.js +2 -14
- package/src/client/websocket/handlers/GUILD_AUDIT_LOG_ENTRY_CREATE.js +2 -17
- package/src/client/websocket/handlers/GUILD_BAN_ADD.js +2 -13
- package/src/client/websocket/handlers/GUILD_BAN_REMOVE.js +2 -18
- package/src/client/websocket/handlers/GUILD_CREATE.js +5 -7
- package/src/client/websocket/handlers/GUILD_DELETE.js +2 -34
- package/src/client/websocket/handlers/GUILD_INTEGRATIONS_UPDATE.js +2 -13
- package/src/client/websocket/handlers/GUILD_MEMBERS_CHUNK.js +1 -3
- package/src/client/websocket/handlers/GUILD_MEMBER_ADD.js +11 -9
- package/src/client/websocket/handlers/GUILD_MEMBER_REMOVE.js +2 -2
- package/src/client/websocket/handlers/GUILD_MEMBER_UPDATE.js +2 -2
- package/src/client/websocket/handlers/GUILD_ROLE_UPDATE.js +2 -19
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_CREATE.js +2 -15
- package/src/client/websocket/handlers/GUILD_SCHEDULED_EVENT_UPDATE.js +2 -17
- package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUNDS_UPDATE.js +1 -2
- package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_CREATE.js +1 -2
- package/src/client/websocket/handlers/GUILD_SOUNDBOARD_SOUND_UPDATE.js +1 -2
- package/src/client/websocket/handlers/INVITE_CREATE.js +2 -18
- package/src/client/websocket/handlers/INVITE_DELETE.js +2 -21
- package/src/client/websocket/handlers/MESSAGE_UPDATE.js +1 -2
- package/src/client/websocket/handlers/PRESENCE_UPDATE.js +2 -40
- package/src/client/websocket/handlers/RATE_LIMITED.js +2 -1
- package/src/client/websocket/handlers/READY.js +5 -8
- package/src/client/websocket/handlers/RESUMED.js +14 -0
- package/src/client/websocket/handlers/SOUNDBOARD_SOUNDS.js +1 -2
- package/src/client/websocket/handlers/SUBSCRIPTION_CREATE.js +1 -2
- package/src/client/websocket/handlers/SUBSCRIPTION_DELETE.js +1 -2
- package/src/client/websocket/handlers/SUBSCRIPTION_UPDATE.js +1 -2
- package/src/client/websocket/handlers/THREAD_DELETE.js +2 -15
- package/src/client/websocket/handlers/THREAD_LIST_SYNC.js +2 -49
- package/src/client/websocket/handlers/THREAD_MEMBER_UPDATE.js +2 -23
- package/src/client/websocket/handlers/THREAD_UPDATE.js +1 -2
- package/src/client/websocket/handlers/VOICE_CHANNEL_EFFECT_SEND.js +2 -3
- package/src/client/websocket/handlers/VOICE_SERVER_UPDATE.js +3 -30
- package/src/client/websocket/handlers/VOICE_STATE_UPDATE.js +2 -35
- package/src/client/websocket/handlers/WEBHOOKS_UPDATE.js +2 -14
- package/src/client/websocket/handlers/index.js +75 -74
- package/src/errors/DJSError.js +7 -7
- package/src/errors/ErrorCodes.js +134 -58
- package/src/errors/Messages.js +143 -115
- package/src/errors/index.js +3 -5
- package/src/index.js +226 -234
- package/src/managers/ApplicationCommandManager.js +24 -60
- package/src/managers/ApplicationCommandPermissionsManager.js +33 -57
- package/src/managers/ApplicationEmojiManager.js +8 -18
- package/src/managers/AutoModerationRuleManager.js +6 -24
- package/src/managers/BaseGuildEmojiManager.js +85 -0
- package/src/managers/BaseManager.js +1 -3
- package/src/managers/CachedManager.js +8 -12
- package/src/managers/CategoryChannelChildManager.js +4 -10
- package/src/managers/ChannelManager.js +8 -70
- package/src/managers/DMMessageManager.js +2 -4
- package/src/managers/DataManager.js +5 -10
- package/src/managers/EntitlementManager.js +8 -19
- package/src/managers/GuildApplicationCommandManager.js +3 -6
- package/src/managers/GuildBanManager.js +52 -27
- package/src/managers/GuildChannelManager.js +54 -91
- package/src/managers/GuildEmojiManager.js +18 -108
- package/src/managers/GuildEmojiRoleManager.js +14 -24
- package/src/managers/GuildForumThreadManager.js +5 -10
- package/src/managers/GuildInviteManager.js +27 -51
- package/src/managers/GuildManager.js +185 -45
- package/src/managers/GuildMemberManager.js +105 -89
- package/src/managers/GuildMemberRoleManager.js +14 -29
- package/src/managers/GuildMessageManager.js +2 -20
- package/src/managers/GuildScheduledEventManager.js +13 -31
- package/src/managers/GuildSoundboardSoundManager.js +5 -17
- package/src/managers/GuildStickerManager.js +21 -34
- package/src/managers/GuildTextThreadManager.js +5 -9
- package/src/managers/MessageManager.js +77 -64
- package/src/managers/PartialGroupDMMessageManager.js +2 -4
- package/src/managers/PermissionOverwriteManager.js +15 -26
- package/src/managers/PollAnswerVoterManager.js +2 -14
- package/src/managers/PresenceManager.js +6 -11
- package/src/managers/ReactionManager.js +6 -13
- package/src/managers/ReactionUserManager.js +4 -11
- package/src/managers/RoleManager.js +74 -76
- package/src/managers/StageInstanceManager.js +8 -18
- package/src/managers/SubscriptionManager.js +4 -9
- package/src/managers/ThreadManager.js +13 -33
- package/src/managers/ThreadMemberManager.js +34 -27
- package/src/managers/UserManager.js +34 -32
- package/src/managers/VoiceStateManager.js +4 -9
- package/src/sharding/Shard.js +40 -64
- package/src/sharding/ShardClientUtil.js +60 -60
- package/src/sharding/ShardingManager.js +30 -89
- package/src/structures/ActionRow.js +18 -6
- package/src/structures/ActionRowBuilder.js +35 -0
- package/src/structures/AnonymousGuild.js +10 -14
- package/src/structures/ApplicationCommand.js +49 -67
- package/src/structures/ApplicationEmoji.js +5 -22
- package/src/structures/ApplicationRoleConnectionMetadata.js +0 -6
- package/src/structures/Attachment.js +7 -25
- package/src/structures/AttachmentBuilder.js +111 -0
- package/src/structures/AutoModerationActionExecution.js +2 -17
- package/src/structures/AutoModerationRule.js +17 -46
- package/src/structures/AutocompleteInteraction.js +4 -14
- package/src/structures/Base.js +2 -4
- package/src/structures/BaseChannel.js +4 -21
- package/src/structures/BaseGuild.js +7 -19
- package/src/structures/BaseGuildEmoji.js +13 -13
- package/src/structures/BaseGuildTextChannel.js +16 -45
- package/src/structures/BaseGuildVoiceChannel.js +12 -43
- package/src/structures/BaseInteraction.js +25 -54
- package/src/structures/BaseSelectMenuComponent.js +2 -8
- package/src/structures/ButtonBuilder.js +44 -0
- package/src/structures/ButtonComponent.js +2 -9
- package/src/structures/ButtonInteraction.js +2 -3
- package/src/structures/CategoryChannel.js +3 -8
- package/src/structures/ChannelSelectMenuBuilder.js +31 -0
- package/src/structures/ChannelSelectMenuComponent.js +2 -4
- package/src/structures/ChannelSelectMenuInteraction.js +2 -5
- package/src/structures/ChatInputCommandInteraction.js +4 -7
- package/src/structures/ClientApplication.js +12 -60
- package/src/structures/ClientPresence.js +10 -15
- package/src/structures/ClientUser.js +19 -36
- package/src/structures/CommandInteraction.js +7 -27
- package/src/structures/CommandInteractionOptionResolver.js +8 -36
- package/src/structures/Component.js +1 -7
- package/src/structures/ContainerComponent.js +3 -9
- package/src/structures/ContextMenuCommandInteraction.js +5 -9
- package/src/structures/DMChannel.js +15 -34
- package/src/structures/DirectoryChannel.js +2 -6
- package/src/structures/Embed.js +2 -19
- package/src/structures/EmbedBuilder.js +50 -0
- package/src/structures/Emoji.js +19 -19
- package/src/structures/Entitlement.js +2 -22
- package/src/structures/FileComponent.js +3 -7
- package/src/structures/ForumChannel.js +3 -6
- package/src/structures/Guild.js +131 -187
- package/src/structures/GuildAuditLogs.js +6 -12
- package/src/structures/GuildAuditLogsEntry.js +63 -88
- package/src/structures/GuildBan.js +3 -9
- package/src/structures/GuildChannel.js +33 -68
- package/src/structures/GuildEmoji.js +7 -19
- package/src/structures/GuildMember.js +58 -107
- package/src/structures/GuildOnboarding.js +2 -9
- package/src/structures/GuildOnboardingPrompt.js +2 -12
- package/src/structures/GuildOnboardingPromptOption.js +2 -12
- package/src/structures/GuildPreview.js +21 -30
- package/src/structures/GuildPreviewEmoji.js +2 -5
- package/src/structures/GuildScheduledEvent.js +19 -59
- package/src/structures/GuildTemplate.js +45 -24
- package/src/structures/Integration.js +7 -30
- package/src/structures/IntegrationApplication.js +12 -9
- package/src/structures/InteractionCallback.js +1 -10
- package/src/structures/InteractionCallbackResource.js +2 -7
- package/src/structures/InteractionCallbackResponse.js +3 -6
- package/src/structures/InteractionCollector.js +36 -23
- package/src/structures/InteractionResponse.js +102 -0
- package/src/structures/InteractionWebhook.js +6 -14
- package/src/structures/Invite.js +341 -0
- package/src/structures/InviteGuild.js +4 -6
- package/src/structures/InviteStageInstance.js +87 -0
- package/src/structures/LabelComponent.js +3 -3
- package/src/structures/MediaChannel.js +2 -3
- package/src/structures/MediaGalleryComponent.js +3 -6
- package/src/structures/MediaGalleryItem.js +2 -7
- package/src/structures/MentionableSelectMenuBuilder.js +32 -0
- package/src/structures/MentionableSelectMenuComponent.js +2 -3
- package/src/structures/MentionableSelectMenuInteraction.js +3 -8
- package/src/structures/Message.js +100 -169
- package/src/structures/MessageCollector.js +5 -16
- package/src/structures/MessageComponentInteraction.js +14 -34
- package/src/structures/MessageContextMenuCommandInteraction.js +2 -4
- package/src/structures/MessageMentions.js +4 -30
- package/src/structures/MessagePayload.js +90 -92
- package/src/structures/MessageReaction.js +17 -31
- package/src/structures/ModalBuilder.js +36 -0
- package/src/structures/{ModalComponentResolver.js → ModalSubmitFields.js} +31 -37
- package/src/structures/ModalSubmitInteraction.js +55 -54
- package/src/structures/NewsChannel.js +32 -0
- package/src/structures/OAuth2Guild.js +3 -6
- package/src/structures/PartialGroupDMChannel.js +11 -23
- package/src/structures/PermissionOverwrites.js +25 -47
- package/src/structures/Poll.js +4 -19
- package/src/structures/PollAnswer.js +29 -13
- package/src/structures/Presence.js +13 -57
- package/src/structures/PrimaryEntryPointCommandInteraction.js +2 -3
- package/src/structures/ReactionCollector.js +4 -21
- package/src/structures/ReactionEmoji.js +3 -5
- package/src/structures/Role.js +48 -65
- package/src/structures/RoleSelectMenuBuilder.js +31 -0
- package/src/structures/RoleSelectMenuComponent.js +2 -3
- package/src/structures/RoleSelectMenuInteraction.js +2 -5
- package/src/structures/SKU.js +2 -9
- package/src/structures/SectionComponent.js +3 -7
- 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/SeparatorComponent.js +2 -5
- package/src/structures/SoundboardSound.js +2 -18
- package/src/structures/StageChannel.js +4 -13
- package/src/structures/StageInstance.js +16 -19
- package/src/structures/Sticker.js +4 -28
- package/src/structures/StickerPack.js +4 -16
- package/src/structures/StringSelectMenuBuilder.js +79 -0
- package/src/structures/StringSelectMenuComponent.js +2 -4
- package/src/structures/StringSelectMenuInteraction.js +2 -4
- package/src/structures/StringSelectMenuOptionBuilder.js +49 -0
- package/src/structures/Subscription.js +1 -15
- package/src/structures/Team.js +7 -16
- package/src/structures/TeamMember.js +15 -9
- package/src/structures/TextChannel.js +3 -6
- package/src/structures/TextDisplayComponent.js +2 -4
- package/src/structures/TextInputBuilder.js +31 -0
- package/src/structures/TextInputComponent.js +2 -5
- package/src/structures/ThreadChannel.js +35 -85
- package/src/structures/ThreadMember.js +12 -17
- package/src/structures/ThreadOnlyChannel.js +15 -36
- package/src/structures/ThumbnailComponent.js +3 -8
- package/src/structures/Typing.js +2 -10
- package/src/structures/UnfurledMediaItem.js +2 -5
- package/src/structures/User.js +68 -60
- package/src/structures/UserContextMenuCommandInteraction.js +2 -5
- package/src/structures/UserSelectMenuBuilder.js +31 -0
- package/src/structures/UserSelectMenuComponent.js +2 -3
- package/src/structures/UserSelectMenuInteraction.js +3 -7
- package/src/structures/VoiceChannel.js +4 -11
- package/src/structures/VoiceChannelEffect.js +2 -12
- package/src/structures/VoiceRegion.js +2 -7
- package/src/structures/VoiceState.js +10 -36
- package/src/structures/Webhook.js +37 -65
- package/src/structures/WelcomeChannel.js +5 -12
- package/src/structures/WelcomeScreen.js +3 -8
- package/src/structures/Widget.js +3 -13
- package/src/structures/WidgetMember.js +2 -17
- package/src/structures/interfaces/Application.js +10 -19
- package/src/structures/interfaces/Collector.js +12 -45
- package/src/structures/interfaces/InteractionResponses.js +152 -43
- package/src/structures/interfaces/TextBasedChannel.js +99 -83
- package/src/util/APITypes.js +16 -30
- package/src/util/ActivityFlagsBitField.js +2 -5
- package/src/util/ApplicationFlagsBitField.js +6 -11
- package/src/util/AttachmentFlagsBitField.js +2 -5
- package/src/util/BitField.js +8 -27
- package/src/util/ChannelFlagsBitField.js +6 -11
- package/src/util/Channels.js +61 -73
- package/src/util/Colors.js +43 -43
- package/src/util/Components.js +82 -61
- package/src/util/Constants.js +124 -94
- package/src/util/DataResolver.js +17 -36
- package/src/util/Enums.js +1 -2
- package/src/util/Events.js +14 -3
- package/src/util/Formatters.js +413 -0
- package/src/util/GuildMemberFlagsBitField.js +5 -9
- package/src/util/IntentsBitField.js +6 -10
- package/src/util/InviteFlagsBitField.js +1 -2
- package/src/util/LimitedCollection.js +6 -13
- package/src/util/LolkaSnowflake.js +14 -1
- package/src/util/MessageFlagsBitField.js +6 -11
- package/src/util/Options.js +57 -35
- package/src/util/Partials.js +4 -5
- package/src/util/PermissionsBitField.js +8 -21
- package/src/util/RoleFlagsBitField.js +2 -5
- package/src/util/SKUFlagsBitField.js +1 -4
- package/src/util/ShardEvents.js +3 -1
- package/src/util/Status.js +21 -5
- package/src/util/Sweepers.js +13 -59
- package/src/util/SystemChannelFlagsBitField.js +6 -11
- package/src/util/ThreadMemberFlagsBitField.js +2 -6
- package/src/util/Transformers.js +18 -17
- package/src/util/UserFlagsBitField.js +2 -6
- package/src/util/Util.js +97 -148
- package/src/util/WebSocketShardEvents.js +25 -0
- package/typings/index.d.mts +2394 -1771
- package/typings/index.d.ts +2394 -1771
- package/typings/rawDataTypes.d.ts +211 -0
- package/src/structures/ActivityInstance.js +0 -52
- package/src/structures/ActivityLocation.js +0 -65
- package/src/structures/AnnouncementChannel.js +0 -29
- package/src/structures/AuthorizingIntegrationOwners.js +0 -64
- package/src/structures/BaseInvite.js +0 -187
- package/src/structures/GroupDMInvite.js +0 -37
- package/src/structures/GuildInvite.js +0 -223
- package/src/util/Invites.js +0 -31
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const EventEmitter = require('node:events');
|
|
3
4
|
const { setTimeout, clearTimeout } = require('node:timers');
|
|
4
5
|
const { Collection } = require('@discordjs/collection');
|
|
5
|
-
const {
|
|
6
|
-
const {
|
|
7
|
-
const { flatten } = require('../../util/Util.js');
|
|
6
|
+
const { DiscordjsTypeError, ErrorCodes } = require('../../errors');
|
|
7
|
+
const { flatten } = require('../../util/Util');
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Filter to be applied to the collector.
|
|
11
|
-
*
|
|
12
11
|
* @typedef {Function} CollectorFilter
|
|
13
12
|
* @param {...*} args Any arguments received by the listener
|
|
14
13
|
* @param {Collection} collection The items collected by this collector
|
|
@@ -17,7 +16,6 @@ const { flatten } = require('../../util/Util.js');
|
|
|
17
16
|
|
|
18
17
|
/**
|
|
19
18
|
* Options to be applied to the collector.
|
|
20
|
-
*
|
|
21
19
|
* @typedef {Object} CollectorOptions
|
|
22
20
|
* @property {CollectorFilter} [filter] The filter applied to this collector
|
|
23
21
|
* @property {number} [time] How long to run the collector for in milliseconds
|
|
@@ -27,17 +25,15 @@ const { flatten } = require('../../util/Util.js');
|
|
|
27
25
|
|
|
28
26
|
/**
|
|
29
27
|
* Abstract class for defining a new Collector.
|
|
30
|
-
*
|
|
31
|
-
* @extends {AsyncEventEmitter}
|
|
28
|
+
* @extends {EventEmitter}
|
|
32
29
|
* @abstract
|
|
33
30
|
*/
|
|
34
|
-
class Collector extends
|
|
31
|
+
class Collector extends EventEmitter {
|
|
35
32
|
constructor(client, options = {}) {
|
|
36
33
|
super();
|
|
37
34
|
|
|
38
35
|
/**
|
|
39
36
|
* The client that instantiated this Collector
|
|
40
|
-
*
|
|
41
37
|
* @name Collector#client
|
|
42
38
|
* @type {Client}
|
|
43
39
|
* @readonly
|
|
@@ -46,7 +42,6 @@ class Collector extends AsyncEventEmitter {
|
|
|
46
42
|
|
|
47
43
|
/**
|
|
48
44
|
* The filter applied to this collector
|
|
49
|
-
*
|
|
50
45
|
* @type {CollectorFilter}
|
|
51
46
|
* @returns {boolean|Promise<boolean>}
|
|
52
47
|
*/
|
|
@@ -54,28 +49,24 @@ class Collector extends AsyncEventEmitter {
|
|
|
54
49
|
|
|
55
50
|
/**
|
|
56
51
|
* The options of this collector
|
|
57
|
-
*
|
|
58
52
|
* @type {CollectorOptions}
|
|
59
53
|
*/
|
|
60
54
|
this.options = options;
|
|
61
55
|
|
|
62
56
|
/**
|
|
63
57
|
* The items collected by this collector
|
|
64
|
-
*
|
|
65
58
|
* @type {Collection}
|
|
66
59
|
*/
|
|
67
60
|
this.collected = new Collection();
|
|
68
61
|
|
|
69
62
|
/**
|
|
70
63
|
* Whether this collector has finished collecting
|
|
71
|
-
*
|
|
72
64
|
* @type {boolean}
|
|
73
65
|
*/
|
|
74
66
|
this.ended = false;
|
|
75
67
|
|
|
76
68
|
/**
|
|
77
69
|
* Timeout for cleanup
|
|
78
|
-
*
|
|
79
70
|
* @type {?Timeout}
|
|
80
71
|
* @private
|
|
81
72
|
*/
|
|
@@ -83,7 +74,6 @@ class Collector extends AsyncEventEmitter {
|
|
|
83
74
|
|
|
84
75
|
/**
|
|
85
76
|
* Timeout for cleanup due to inactivity
|
|
86
|
-
*
|
|
87
77
|
* @type {?Timeout}
|
|
88
78
|
* @private
|
|
89
79
|
*/
|
|
@@ -91,7 +81,6 @@ class Collector extends AsyncEventEmitter {
|
|
|
91
81
|
|
|
92
82
|
/**
|
|
93
83
|
* The reason the collector ended
|
|
94
|
-
*
|
|
95
84
|
* @type {?string}
|
|
96
85
|
* @private
|
|
97
86
|
*/
|
|
@@ -109,7 +98,6 @@ class Collector extends AsyncEventEmitter {
|
|
|
109
98
|
|
|
110
99
|
/**
|
|
111
100
|
* The timestamp at which this collector last collected an item
|
|
112
|
-
*
|
|
113
101
|
* @type {?number}
|
|
114
102
|
*/
|
|
115
103
|
this.lastCollectedTimestamp = null;
|
|
@@ -117,7 +105,6 @@ class Collector extends AsyncEventEmitter {
|
|
|
117
105
|
|
|
118
106
|
/**
|
|
119
107
|
* The Date at which this collector last collected an item
|
|
120
|
-
*
|
|
121
108
|
* @type {?Date}
|
|
122
109
|
*/
|
|
123
110
|
get lastCollectedAt() {
|
|
@@ -126,7 +113,6 @@ class Collector extends AsyncEventEmitter {
|
|
|
126
113
|
|
|
127
114
|
/**
|
|
128
115
|
* Call this to handle an event as a collectable element. Accepts any event data as parameters.
|
|
129
|
-
*
|
|
130
116
|
* @param {...*} args The arguments emitted by the listener
|
|
131
117
|
* @returns {Promise<void>}
|
|
132
118
|
* @emits Collector#collect
|
|
@@ -141,7 +127,6 @@ class Collector extends AsyncEventEmitter {
|
|
|
141
127
|
|
|
142
128
|
/**
|
|
143
129
|
* Emitted whenever an element is collected.
|
|
144
|
-
*
|
|
145
130
|
* @event Collector#collect
|
|
146
131
|
* @param {...*} args The arguments emitted by the listener
|
|
147
132
|
*/
|
|
@@ -155,20 +140,17 @@ class Collector extends AsyncEventEmitter {
|
|
|
155
140
|
} else {
|
|
156
141
|
/**
|
|
157
142
|
* Emitted whenever an element is not collected by the collector.
|
|
158
|
-
*
|
|
159
143
|
* @event Collector#ignore
|
|
160
144
|
* @param {...*} args The arguments emitted by the listener
|
|
161
145
|
*/
|
|
162
146
|
this.emit('ignore', ...args);
|
|
163
147
|
}
|
|
164
148
|
}
|
|
165
|
-
|
|
166
149
|
this.checkEnd();
|
|
167
150
|
}
|
|
168
151
|
|
|
169
152
|
/**
|
|
170
153
|
* Call this to remove an element from the collection. Accepts any event data as parameters.
|
|
171
|
-
*
|
|
172
154
|
* @param {...*} args The arguments emitted by the listener
|
|
173
155
|
* @returns {Promise<void>}
|
|
174
156
|
* @emits Collector#dispose
|
|
@@ -182,7 +164,6 @@ class Collector extends AsyncEventEmitter {
|
|
|
182
164
|
|
|
183
165
|
/**
|
|
184
166
|
* Emitted whenever an element is disposed of.
|
|
185
|
-
*
|
|
186
167
|
* @event Collector#dispose
|
|
187
168
|
* @param {...*} args The arguments emitted by the listener
|
|
188
169
|
*/
|
|
@@ -193,7 +174,6 @@ class Collector extends AsyncEventEmitter {
|
|
|
193
174
|
/**
|
|
194
175
|
* Returns a promise that resolves with the next collected element;
|
|
195
176
|
* rejects with collected elements if the collector finishes without receiving a next element
|
|
196
|
-
*
|
|
197
177
|
* @type {Promise}
|
|
198
178
|
* @readonly
|
|
199
179
|
*/
|
|
@@ -205,9 +185,7 @@ class Collector extends AsyncEventEmitter {
|
|
|
205
185
|
}
|
|
206
186
|
|
|
207
187
|
const cleanup = () => {
|
|
208
|
-
// eslint-disable-next-line no-use-before-define
|
|
209
188
|
this.removeListener('collect', onCollect);
|
|
210
|
-
// eslint-disable-next-line no-use-before-define
|
|
211
189
|
this.removeListener('end', onEnd);
|
|
212
190
|
};
|
|
213
191
|
|
|
@@ -228,7 +206,6 @@ class Collector extends AsyncEventEmitter {
|
|
|
228
206
|
|
|
229
207
|
/**
|
|
230
208
|
* Stops this collector and emits the `end` event.
|
|
231
|
-
*
|
|
232
209
|
* @param {string} [reason='user'] The reason this collector is ending
|
|
233
210
|
* @emits Collector#end
|
|
234
211
|
*/
|
|
@@ -239,7 +216,6 @@ class Collector extends AsyncEventEmitter {
|
|
|
239
216
|
clearTimeout(this._timeout);
|
|
240
217
|
this._timeout = null;
|
|
241
218
|
}
|
|
242
|
-
|
|
243
219
|
if (this._idletimeout) {
|
|
244
220
|
clearTimeout(this._idletimeout);
|
|
245
221
|
this._idletimeout = null;
|
|
@@ -250,7 +226,6 @@ class Collector extends AsyncEventEmitter {
|
|
|
250
226
|
|
|
251
227
|
/**
|
|
252
228
|
* Emitted when the collector is finished collecting.
|
|
253
|
-
*
|
|
254
229
|
* @event Collector#end
|
|
255
230
|
* @param {Collection} collected The elements collected by the collector
|
|
256
231
|
* @param {string} reason The reason the collector ended
|
|
@@ -260,7 +235,6 @@ class Collector extends AsyncEventEmitter {
|
|
|
260
235
|
|
|
261
236
|
/**
|
|
262
237
|
* Options used to reset the timeout and idle timer of a {@link Collector}.
|
|
263
|
-
*
|
|
264
238
|
* @typedef {Object} CollectorResetTimerOptions
|
|
265
239
|
* @property {number} [time] How long to run the collector for (in milliseconds)
|
|
266
240
|
* @property {number} [idle] How long to wait to stop the collector after inactivity (in milliseconds)
|
|
@@ -268,7 +242,6 @@ class Collector extends AsyncEventEmitter {
|
|
|
268
242
|
|
|
269
243
|
/**
|
|
270
244
|
* Resets the collector's timeout and idle timer.
|
|
271
|
-
*
|
|
272
245
|
* @param {CollectorResetTimerOptions} [options] Options for resetting
|
|
273
246
|
*/
|
|
274
247
|
resetTimer({ time, idle } = {}) {
|
|
@@ -276,7 +249,6 @@ class Collector extends AsyncEventEmitter {
|
|
|
276
249
|
clearTimeout(this._timeout);
|
|
277
250
|
this._timeout = setTimeout(() => this.stop('time'), time ?? this.options.time).unref();
|
|
278
251
|
}
|
|
279
|
-
|
|
280
252
|
if (this._idletimeout) {
|
|
281
253
|
clearTimeout(this._idletimeout);
|
|
282
254
|
this._idletimeout = setTimeout(() => this.stop('idle'), idle ?? this.options.idle).unref();
|
|
@@ -285,7 +257,6 @@ class Collector extends AsyncEventEmitter {
|
|
|
285
257
|
|
|
286
258
|
/**
|
|
287
259
|
* Checks whether the collector should end, and if so, ends it.
|
|
288
|
-
*
|
|
289
260
|
* @returns {boolean} Whether the collector ended or not
|
|
290
261
|
*/
|
|
291
262
|
checkEnd() {
|
|
@@ -296,7 +267,6 @@ class Collector extends AsyncEventEmitter {
|
|
|
296
267
|
|
|
297
268
|
/**
|
|
298
269
|
* Allows collectors to be consumed with for-await-of loops
|
|
299
|
-
*
|
|
300
270
|
* @see {@link https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/for-await...of}
|
|
301
271
|
*/
|
|
302
272
|
async *[Symbol.asyncIterator]() {
|
|
@@ -309,13 +279,13 @@ class Collector extends AsyncEventEmitter {
|
|
|
309
279
|
if (queue.length) {
|
|
310
280
|
yield queue.shift();
|
|
311
281
|
} else {
|
|
282
|
+
// eslint-disable-next-line no-await-in-loop
|
|
312
283
|
await new Promise(resolve => {
|
|
313
284
|
const tick = () => {
|
|
314
285
|
this.removeListener('collect', tick);
|
|
315
286
|
this.removeListener('end', tick);
|
|
316
|
-
resolve();
|
|
287
|
+
return resolve();
|
|
317
288
|
};
|
|
318
|
-
|
|
319
289
|
this.on('collect', tick);
|
|
320
290
|
this.on('end', tick);
|
|
321
291
|
});
|
|
@@ -330,9 +300,9 @@ class Collector extends AsyncEventEmitter {
|
|
|
330
300
|
return flatten(this);
|
|
331
301
|
}
|
|
332
302
|
|
|
303
|
+
/* eslint-disable no-empty-function */
|
|
333
304
|
/**
|
|
334
305
|
* The reason this collector has ended with, or null if it hasn't ended yet
|
|
335
|
-
*
|
|
336
306
|
* @type {?string}
|
|
337
307
|
* @readonly
|
|
338
308
|
*/
|
|
@@ -343,26 +313,23 @@ class Collector extends AsyncEventEmitter {
|
|
|
343
313
|
/**
|
|
344
314
|
* Handles incoming events from the `handleCollect` function. Returns null if the event should not
|
|
345
315
|
* be collected, or returns an object describing the data that should be stored.
|
|
346
|
-
*
|
|
347
316
|
* @see Collector#handleCollect
|
|
348
317
|
* @param {...*} args Any args the event listener emits
|
|
349
318
|
* @returns {?(*|Promise<?*>)} Data to insert into collection, if any
|
|
350
319
|
* @abstract
|
|
351
320
|
*/
|
|
352
|
-
|
|
353
|
-
collect(...args) {}
|
|
321
|
+
collect() {}
|
|
354
322
|
|
|
355
323
|
/**
|
|
356
324
|
* Handles incoming events from the `handleDispose`. Returns null if the event should not
|
|
357
325
|
* be disposed, or returns the key that should be removed.
|
|
358
|
-
*
|
|
359
326
|
* @see Collector#handleDispose
|
|
360
327
|
* @param {...*} args Any args the event listener emits
|
|
361
328
|
* @returns {?*} Key to remove from the collection, if any
|
|
362
329
|
* @abstract
|
|
363
330
|
*/
|
|
364
|
-
|
|
365
|
-
|
|
331
|
+
dispose() {}
|
|
332
|
+
/* eslint-enable no-empty-function */
|
|
366
333
|
}
|
|
367
334
|
|
|
368
|
-
exports
|
|
335
|
+
module.exports = Collector;
|
|
@@ -1,73 +1,83 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const process = require('node:process');
|
|
4
|
+
const { deprecate } = require('node:util');
|
|
3
5
|
const { makeURLSearchParams } = require('@discordjs/rest');
|
|
4
6
|
const { isJSONEncodable } = require('@discordjs/util');
|
|
5
7
|
const { InteractionResponseType, MessageFlags, Routes, InteractionType } = require('discord-api-types/v10');
|
|
6
|
-
const { DiscordjsError, ErrorCodes } = require('../../errors
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
8
|
+
const { DiscordjsError, ErrorCodes } = require('../../errors');
|
|
9
|
+
const MessageFlagsBitField = require('../../util/MessageFlagsBitField');
|
|
10
|
+
const InteractionCallbackResponse = require('../InteractionCallbackResponse');
|
|
11
|
+
const InteractionCollector = require('../InteractionCollector');
|
|
12
|
+
const InteractionResponse = require('../InteractionResponse');
|
|
13
|
+
const MessagePayload = require('../MessagePayload');
|
|
14
|
+
|
|
15
|
+
let deprecationEmittedForEphemeralOption = false;
|
|
16
|
+
let deprecationEmittedForFetchReplyOption = false;
|
|
11
17
|
|
|
12
18
|
/**
|
|
13
19
|
* Interface for classes that support shared interaction response types.
|
|
14
|
-
*
|
|
15
20
|
* @interface
|
|
16
21
|
*/
|
|
17
22
|
class InteractionResponses {
|
|
18
23
|
/**
|
|
19
24
|
* Options for deferring the reply to an {@link BaseInteraction}.
|
|
20
|
-
*
|
|
21
25
|
* @typedef {Object} InteractionDeferReplyOptions
|
|
22
|
-
* @property {boolean} [
|
|
26
|
+
* @property {boolean} [ephemeral] Whether the reply should be ephemeral.
|
|
27
|
+
* <warn>This option is deprecated. Use `flags` instead.</warn>
|
|
23
28
|
* @property {MessageFlagsResolvable} [flags] Flags for the reply.
|
|
24
29
|
* <info>Only `MessageFlags.Ephemeral` can be set.</info>
|
|
30
|
+
* @property {boolean} [withResponse] Whether to return an {@link InteractionCallbackResponse} as the response
|
|
31
|
+
* @property {boolean} [fetchReply] Whether to fetch the reply
|
|
32
|
+
* <warn>This option is deprecated. Use `withResponse` or fetch the response instead.</warn>
|
|
25
33
|
*/
|
|
26
34
|
|
|
27
35
|
/**
|
|
28
36
|
* Options for deferring and updating the reply to a {@link MessageComponentInteraction}.
|
|
29
|
-
*
|
|
30
37
|
* @typedef {Object} InteractionDeferUpdateOptions
|
|
31
38
|
* @property {boolean} [withResponse] Whether to return an {@link InteractionCallbackResponse} as the response
|
|
39
|
+
* @property {boolean} [fetchReply] Whether to fetch the reply
|
|
40
|
+
* <warn>This option is deprecated. Use `withResponse` or fetch the response instead.</warn>
|
|
32
41
|
*/
|
|
33
42
|
|
|
34
43
|
/**
|
|
35
44
|
* Options for a reply to a {@link BaseInteraction}.
|
|
36
|
-
*
|
|
37
45
|
* @typedef {BaseMessageOptionsWithPoll} InteractionReplyOptions
|
|
46
|
+
* @property {boolean} [ephemeral] Whether the reply should be ephemeral.
|
|
47
|
+
* <warn>This option is deprecated. Use `flags` instead.</warn>
|
|
38
48
|
* @property {boolean} [tts=false] Whether the message should be spoken aloud
|
|
39
49
|
* @property {boolean} [withResponse] Whether to return an {@link InteractionCallbackResponse} as the response
|
|
50
|
+
* @property {boolean} [fetchReply] Whether to fetch the reply
|
|
51
|
+
* <warn>This option is deprecated. Use `withResponse` or fetch the response instead.</warn>
|
|
40
52
|
* @property {MessageFlagsResolvable} [flags] Which flags to set for the message.
|
|
41
|
-
* <info>Only
|
|
42
|
-
*
|
|
53
|
+
* <info>Only `MessageFlags.Ephemeral`, `MessageFlags.SuppressEmbeds`, and `MessageFlags.SuppressNotifications`
|
|
54
|
+
* can be set.</info>
|
|
43
55
|
*/
|
|
44
56
|
|
|
45
57
|
/**
|
|
46
58
|
* Options for updating the message received from a {@link MessageComponentInteraction}.
|
|
47
|
-
*
|
|
48
59
|
* @typedef {MessageEditOptions} InteractionUpdateOptions
|
|
49
60
|
* @property {boolean} [withResponse] Whether to return an {@link InteractionCallbackResponse} as the response
|
|
61
|
+
* @property {boolean} [fetchReply] Whether to fetch the reply
|
|
62
|
+
* <warn>This option is deprecated. Use `withResponse` or fetch the response instead.</warn>
|
|
50
63
|
*/
|
|
51
64
|
|
|
52
65
|
/**
|
|
53
66
|
* Options for launching activity in response to a {@link BaseInteraction}
|
|
54
|
-
*
|
|
55
67
|
* @typedef {Object} LaunchActivityOptions
|
|
56
68
|
* @property {boolean} [withResponse] Whether to return an {@link InteractionCallbackResponse} as the response
|
|
57
69
|
*/
|
|
58
70
|
|
|
59
71
|
/**
|
|
60
72
|
* Options for showing a modal in response to a {@link BaseInteraction}
|
|
61
|
-
*
|
|
62
73
|
* @typedef {Object} ShowModalOptions
|
|
63
74
|
* @property {boolean} [withResponse] Whether to return an {@link InteractionCallbackResponse} as the response
|
|
64
75
|
*/
|
|
65
76
|
|
|
66
77
|
/**
|
|
67
78
|
* Defers the reply to this interaction.
|
|
68
|
-
*
|
|
69
79
|
* @param {InteractionDeferReplyOptions} [options] Options for deferring the reply to this interaction
|
|
70
|
-
* @returns {Promise<InteractionCallbackResponse|
|
|
80
|
+
* @returns {Promise<InteractionCallbackResponse|Message|InteractionResponse>}
|
|
71
81
|
* @example
|
|
72
82
|
* // Defer the reply to this interaction
|
|
73
83
|
* interaction.deferReply()
|
|
@@ -82,13 +92,38 @@ class InteractionResponses {
|
|
|
82
92
|
async deferReply(options = {}) {
|
|
83
93
|
if (this.deferred || this.replied) throw new DiscordjsError(ErrorCodes.InteractionAlreadyReplied);
|
|
84
94
|
|
|
85
|
-
|
|
95
|
+
if ('ephemeral' in options) {
|
|
96
|
+
if (!deprecationEmittedForEphemeralOption) {
|
|
97
|
+
process.emitWarning(
|
|
98
|
+
`Supplying "ephemeral" for interaction response options is deprecated. Utilize flags instead.`,
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
deprecationEmittedForEphemeralOption = true;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if ('fetchReply' in options) {
|
|
106
|
+
if (!deprecationEmittedForFetchReplyOption) {
|
|
107
|
+
process.emitWarning(
|
|
108
|
+
// eslint-disable-next-line max-len
|
|
109
|
+
`Supplying "fetchReply" for interaction response options is deprecated. Utilize "withResponse" instead or fetch the response after using the method.`,
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
deprecationEmittedForFetchReplyOption = true;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const flags = new MessageFlagsBitField(options.flags);
|
|
117
|
+
|
|
118
|
+
if (options.ephemeral) {
|
|
119
|
+
flags.add(MessageFlags.Ephemeral);
|
|
120
|
+
}
|
|
86
121
|
|
|
87
122
|
const response = await this.client.rest.post(Routes.interactionCallback(this.id, this.token), {
|
|
88
123
|
body: {
|
|
89
124
|
type: InteractionResponseType.DeferredChannelMessageWithSource,
|
|
90
125
|
data: {
|
|
91
|
-
flags:
|
|
126
|
+
flags: flags.bitfield,
|
|
92
127
|
},
|
|
93
128
|
},
|
|
94
129
|
auth: false,
|
|
@@ -96,17 +131,20 @@ class InteractionResponses {
|
|
|
96
131
|
});
|
|
97
132
|
|
|
98
133
|
this.deferred = true;
|
|
99
|
-
this.ephemeral =
|
|
134
|
+
this.ephemeral = flags.has(MessageFlags.Ephemeral);
|
|
100
135
|
|
|
101
|
-
return options.withResponse
|
|
136
|
+
return options.withResponse
|
|
137
|
+
? new InteractionCallbackResponse(this.client, response)
|
|
138
|
+
: options.fetchReply
|
|
139
|
+
? this.fetchReply()
|
|
140
|
+
: new InteractionResponse(this);
|
|
102
141
|
}
|
|
103
142
|
|
|
104
143
|
/**
|
|
105
144
|
* Creates a reply to this interaction.
|
|
106
145
|
* <info>Use the `withResponse` option to get the interaction callback response.</info>
|
|
107
|
-
*
|
|
108
146
|
* @param {string|MessagePayload|InteractionReplyOptions} options The options for the reply
|
|
109
|
-
* @returns {Promise<InteractionCallbackResponse|
|
|
147
|
+
* @returns {Promise<InteractionCallbackResponse|Message|InteractionResponse>}
|
|
110
148
|
* @example
|
|
111
149
|
* // Reply to the interaction and fetch the response
|
|
112
150
|
* interaction.reply({ content: 'Pong!', withResponse: true })
|
|
@@ -123,6 +161,29 @@ class InteractionResponses {
|
|
|
123
161
|
async reply(options) {
|
|
124
162
|
if (this.deferred || this.replied) throw new DiscordjsError(ErrorCodes.InteractionAlreadyReplied);
|
|
125
163
|
|
|
164
|
+
if (typeof options !== 'string') {
|
|
165
|
+
if ('ephemeral' in options) {
|
|
166
|
+
if (!deprecationEmittedForEphemeralOption) {
|
|
167
|
+
process.emitWarning(
|
|
168
|
+
`Supplying "ephemeral" for interaction response options is deprecated. Utilize flags instead.`,
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
deprecationEmittedForEphemeralOption = true;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if ('fetchReply' in options) {
|
|
176
|
+
if (!deprecationEmittedForFetchReplyOption) {
|
|
177
|
+
process.emitWarning(
|
|
178
|
+
// eslint-disable-next-line max-len
|
|
179
|
+
`Supplying "fetchReply" for interaction response options is deprecated. Utilize "withResponse" instead or fetch the response after using the method.`,
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
deprecationEmittedForFetchReplyOption = true;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
126
187
|
let messagePayload;
|
|
127
188
|
if (options instanceof MessagePayload) messagePayload = options;
|
|
128
189
|
else messagePayload = MessagePayload.create(this, options);
|
|
@@ -142,12 +203,15 @@ class InteractionResponses {
|
|
|
142
203
|
this.ephemeral = Boolean(data.flags & MessageFlags.Ephemeral);
|
|
143
204
|
this.replied = true;
|
|
144
205
|
|
|
145
|
-
return options.withResponse
|
|
206
|
+
return options.withResponse
|
|
207
|
+
? new InteractionCallbackResponse(this.client, response)
|
|
208
|
+
: options.fetchReply
|
|
209
|
+
? this.fetchReply()
|
|
210
|
+
: new InteractionResponse(this);
|
|
146
211
|
}
|
|
147
212
|
|
|
148
213
|
/**
|
|
149
214
|
* Fetches a reply to this interaction.
|
|
150
|
-
*
|
|
151
215
|
* @see Webhook#fetchMessage
|
|
152
216
|
* @param {Snowflake|'@original'} [message='@original'] The response to fetch
|
|
153
217
|
* @returns {Promise<Message>}
|
|
@@ -157,20 +221,18 @@ class InteractionResponses {
|
|
|
157
221
|
* .then(reply => console.log(`Replied with ${reply.content}`))
|
|
158
222
|
* .catch(console.error);
|
|
159
223
|
*/
|
|
160
|
-
|
|
224
|
+
fetchReply(message = '@original') {
|
|
161
225
|
return this.webhook.fetchMessage(message);
|
|
162
226
|
}
|
|
163
227
|
|
|
164
228
|
/**
|
|
165
229
|
* Options that can be passed into {@link InteractionResponses#editReply}.
|
|
166
|
-
*
|
|
167
230
|
* @typedef {WebhookMessageEditOptions} InteractionEditReplyOptions
|
|
168
231
|
* @property {MessageResolvable|'@original'} [message='@original'] The response to edit
|
|
169
232
|
*/
|
|
170
233
|
|
|
171
234
|
/**
|
|
172
235
|
* Edits a reply to this interaction.
|
|
173
|
-
*
|
|
174
236
|
* @see Webhook#editMessage
|
|
175
237
|
* @param {string|MessagePayload|InteractionEditReplyOptions} options The new options for the message
|
|
176
238
|
* @returns {Promise<Message>}
|
|
@@ -189,7 +251,6 @@ class InteractionResponses {
|
|
|
189
251
|
|
|
190
252
|
/**
|
|
191
253
|
* Deletes a reply to this interaction.
|
|
192
|
-
*
|
|
193
254
|
* @see Webhook#deleteMessage
|
|
194
255
|
* @param {MessageResolvable|'@original'} [message='@original'] The response to delete
|
|
195
256
|
* @returns {Promise<void>}
|
|
@@ -207,7 +268,6 @@ class InteractionResponses {
|
|
|
207
268
|
|
|
208
269
|
/**
|
|
209
270
|
* Send a follow-up message to this interaction.
|
|
210
|
-
*
|
|
211
271
|
* @param {string|MessagePayload|InteractionReplyOptions} options The options for the reply
|
|
212
272
|
* @returns {Promise<Message>}
|
|
213
273
|
*/
|
|
@@ -220,9 +280,8 @@ class InteractionResponses {
|
|
|
220
280
|
|
|
221
281
|
/**
|
|
222
282
|
* Defers an update to the message to which the component was attached.
|
|
223
|
-
*
|
|
224
283
|
* @param {InteractionDeferUpdateOptions} [options] Options for deferring the update to this interaction
|
|
225
|
-
* @returns {Promise<InteractionCallbackResponse|
|
|
284
|
+
* @returns {Promise<InteractionCallbackResponse|Message|InteractionResponse>}
|
|
226
285
|
* @example
|
|
227
286
|
* // Defer updating and reset the component's loading state
|
|
228
287
|
* interaction.deferUpdate()
|
|
@@ -231,6 +290,18 @@ class InteractionResponses {
|
|
|
231
290
|
*/
|
|
232
291
|
async deferUpdate(options = {}) {
|
|
233
292
|
if (this.deferred || this.replied) throw new DiscordjsError(ErrorCodes.InteractionAlreadyReplied);
|
|
293
|
+
|
|
294
|
+
if ('fetchReply' in options) {
|
|
295
|
+
if (!deprecationEmittedForFetchReplyOption) {
|
|
296
|
+
process.emitWarning(
|
|
297
|
+
// eslint-disable-next-line max-len
|
|
298
|
+
`Supplying "fetchReply" for interaction response options is deprecated. Utilize "withResponse" instead or fetch the response after using the method.`,
|
|
299
|
+
);
|
|
300
|
+
|
|
301
|
+
deprecationEmittedForFetchReplyOption = true;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
234
305
|
const response = await this.client.rest.post(Routes.interactionCallback(this.id, this.token), {
|
|
235
306
|
body: {
|
|
236
307
|
type: InteractionResponseType.DeferredMessageUpdate,
|
|
@@ -240,14 +311,17 @@ class InteractionResponses {
|
|
|
240
311
|
});
|
|
241
312
|
this.deferred = true;
|
|
242
313
|
|
|
243
|
-
return options.withResponse
|
|
314
|
+
return options.withResponse
|
|
315
|
+
? new InteractionCallbackResponse(this.client, response)
|
|
316
|
+
: options.fetchReply
|
|
317
|
+
? this.fetchReply()
|
|
318
|
+
: new InteractionResponse(this, this.message?.interactionMetadata?.id);
|
|
244
319
|
}
|
|
245
320
|
|
|
246
321
|
/**
|
|
247
322
|
* Updates the original message of the component on which the interaction was received on.
|
|
248
|
-
*
|
|
249
|
-
* @
|
|
250
|
-
* @returns {Promise<InteractionCallbackResponse|undefined>}
|
|
323
|
+
* @param {string|MessagePayload|InteractionUpdateOptions} options The options for the updated message
|
|
324
|
+
* @returns {Promise<InteractionCallbackResponse|Message|void>}
|
|
251
325
|
* @example
|
|
252
326
|
* // Remove the components from the message
|
|
253
327
|
* interaction.update({
|
|
@@ -257,9 +331,20 @@ class InteractionResponses {
|
|
|
257
331
|
* .then(console.log)
|
|
258
332
|
* .catch(console.error);
|
|
259
333
|
*/
|
|
260
|
-
async update(options
|
|
334
|
+
async update(options) {
|
|
261
335
|
if (this.deferred || this.replied) throw new DiscordjsError(ErrorCodes.InteractionAlreadyReplied);
|
|
262
336
|
|
|
337
|
+
if (typeof options !== 'string' && 'fetchReply' in options) {
|
|
338
|
+
if (!deprecationEmittedForFetchReplyOption) {
|
|
339
|
+
process.emitWarning(
|
|
340
|
+
// eslint-disable-next-line max-len
|
|
341
|
+
`Supplying "fetchReply" for interaction response options is deprecated. Utilize "withResponse" instead or fetch the response after using the method.`,
|
|
342
|
+
);
|
|
343
|
+
|
|
344
|
+
deprecationEmittedForFetchReplyOption = true;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
263
348
|
let messagePayload;
|
|
264
349
|
if (options instanceof MessagePayload) messagePayload = options;
|
|
265
350
|
else messagePayload = MessagePayload.create(this, options);
|
|
@@ -277,12 +362,15 @@ class InteractionResponses {
|
|
|
277
362
|
});
|
|
278
363
|
this.replied = true;
|
|
279
364
|
|
|
280
|
-
return options.withResponse
|
|
365
|
+
return options.withResponse
|
|
366
|
+
? new InteractionCallbackResponse(this.client, response)
|
|
367
|
+
: options.fetchReply
|
|
368
|
+
? this.fetchReply()
|
|
369
|
+
: new InteractionResponse(this, this.message.interactionMetadata?.id);
|
|
281
370
|
}
|
|
282
371
|
|
|
283
372
|
/**
|
|
284
373
|
* Launches this application's activity, if enabled
|
|
285
|
-
*
|
|
286
374
|
* @param {LaunchActivityOptions} [options={}] Options for launching the activity
|
|
287
375
|
* @returns {Promise<InteractionCallbackResponse|undefined>}
|
|
288
376
|
*/
|
|
@@ -302,7 +390,6 @@ class InteractionResponses {
|
|
|
302
390
|
|
|
303
391
|
/**
|
|
304
392
|
* Shows a modal component
|
|
305
|
-
*
|
|
306
393
|
* @param {ModalBuilder|ModalComponentData|APIModalInteractionResponseCallbackData} modal The modal to show
|
|
307
394
|
* @param {ShowModalOptions} [options={}] The options for sending this interaction response
|
|
308
395
|
* @returns {Promise<InteractionCallbackResponse|undefined>}
|
|
@@ -322,9 +409,25 @@ class InteractionResponses {
|
|
|
322
409
|
return options.withResponse ? new InteractionCallbackResponse(this.client, response) : undefined;
|
|
323
410
|
}
|
|
324
411
|
|
|
412
|
+
/**
|
|
413
|
+
* Responds to the interaction with an upgrade button.
|
|
414
|
+
* <info>Only available for applications with monetization enabled.</info>
|
|
415
|
+
* @deprecated Sending a premium-style button is the new Discord behaviour.
|
|
416
|
+
* @returns {Promise<void>}
|
|
417
|
+
*/
|
|
418
|
+
async sendPremiumRequired() {
|
|
419
|
+
if (this.deferred || this.replied) throw new DiscordjsError(ErrorCodes.InteractionAlreadyReplied);
|
|
420
|
+
await this.client.rest.post(Routes.interactionCallback(this.id, this.token), {
|
|
421
|
+
body: {
|
|
422
|
+
type: InteractionResponseType.PremiumRequired,
|
|
423
|
+
},
|
|
424
|
+
auth: false,
|
|
425
|
+
});
|
|
426
|
+
this.replied = true;
|
|
427
|
+
}
|
|
428
|
+
|
|
325
429
|
/**
|
|
326
430
|
* An object containing the same properties as {@link CollectorOptions}, but a few less:
|
|
327
|
-
*
|
|
328
431
|
* @typedef {Object} AwaitModalSubmitOptions
|
|
329
432
|
* @property {CollectorFilter} [filter] The filter applied to this collector
|
|
330
433
|
* @property {number} time Time in milliseconds to wait for an interaction before rejecting
|
|
@@ -333,7 +436,6 @@ class InteractionResponses {
|
|
|
333
436
|
/**
|
|
334
437
|
* Collects a single modal submit interaction that passes the filter.
|
|
335
438
|
* The Promise will reject if the time expires.
|
|
336
|
-
*
|
|
337
439
|
* @param {AwaitModalSubmitOptions} options Options to pass to the internal collector
|
|
338
440
|
* @returns {Promise<ModalSubmitInteraction>}
|
|
339
441
|
* @example
|
|
@@ -368,6 +470,7 @@ class InteractionResponses {
|
|
|
368
470
|
'update',
|
|
369
471
|
'launchActivity',
|
|
370
472
|
'showModal',
|
|
473
|
+
'sendPremiumRequired',
|
|
371
474
|
'awaitModalSubmit',
|
|
372
475
|
];
|
|
373
476
|
|
|
@@ -382,4 +485,10 @@ class InteractionResponses {
|
|
|
382
485
|
}
|
|
383
486
|
}
|
|
384
487
|
|
|
385
|
-
|
|
488
|
+
InteractionResponses.prototype.sendPremiumRequired = deprecate(
|
|
489
|
+
InteractionResponses.prototype.sendPremiumRequired,
|
|
490
|
+
// eslint-disable-next-line max-len
|
|
491
|
+
'InteractionResponses#sendPremiumRequired() is deprecated. Sending a premium-style button is the new Discord behaviour.',
|
|
492
|
+
);
|
|
493
|
+
|
|
494
|
+
module.exports = InteractionResponses;
|