From 42bcf8761fe9c066afe124a79de4351713b165b3 Mon Sep 17 00:00:00 2001 From: March 7th <71698422+aiko-chan-ai@users.noreply.github.com> Date: Sun, 18 Dec 2022 13:17:48 +0700 Subject: [PATCH] feat: new select menus fix --- src/util/Constants.js | 21 +++++++++++++++++++++ typings/enums.d.ts | 8 ++++++++ typings/index.d.ts | 40 +++++++++++++++++++++++++++++++--------- 3 files changed, 60 insertions(+), 9 deletions(-) diff --git a/src/util/Constants.js b/src/util/Constants.js index c030521..b1f2ed1 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -1531,6 +1531,26 @@ exports.MessageComponentTypes = createEnum([ 'CHANNEL_SELECT', ]); +/** + * The types of components that are select menus. The available types are: + * * STRING_MENU + * * USER_SELECT + * * ROLE_SELECT + * * MENTIONABLE_SELECT + * * CHANNEL_SELECT + * @typedef {string} SelectMenuComponentType + * @see {@link https://discord.com/developers/docs/interactions/message-components#component-object-component-types} + */ +exports.SelectMenuComponentTypes = createEnum([ + ...new Array(3).fill(null), + 'STRING_MENU', + null, + 'USER_SELECT', + 'ROLE_SELECT', + 'MENTIONABLE_SELECT', + 'CHANNEL_SELECT', +]); + /** * The style of a message button * * PRIMARY @@ -1712,6 +1732,7 @@ function createEnum(keys) { * @property {Object} MembershipStates The value set for a team members membership state. * @property {Object} MessageButtonStyles The style of a message button. * @property {Object} MessageComponentTypes The type of a message component. + * @property {Object} SelectMenuComponentTypes The type of any select menu * @property {Object} MFALevels The required MFA level for a guild. * @property {Object} NSFWLevels NSFW level of a guild. * @property {Opcodes} Opcodes The types of Opcodes sent to the Gateway. diff --git a/typings/enums.d.ts b/typings/enums.d.ts index 73a5fd7..d800df5 100644 --- a/typings/enums.d.ts +++ b/typings/enums.d.ts @@ -226,6 +226,14 @@ export const enum MessageComponentTypes { CHANNEL_SELECT = 8, } +export const enum SelectMenuComponentTypes { + STRING_SELECT = 3, + USER_SELECT = 5, + ROLE_SELECT = 6, + MENTIONABLE_SELECT = 7, + CHANNEL_SELECT = 8, +} + export const enum ModalComponentTypes { ACTION_ROW = 1, TEXT_INPUT = 4, diff --git a/typings/index.d.ts b/typings/index.d.ts index ec3bd8a..7befd44 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -100,6 +100,7 @@ import { HypeSquadType, VideoQualityModes, SortOrderType, + SelectMenuComponentTypes, } from './enums'; import { RawActivityData, @@ -1873,8 +1874,8 @@ export type AwaitMessageCollectorOptionsParams< export interface StringMappedInteractionTypes { BUTTON: ButtonInteraction; - STRING_SELECT: SelectMenuInteraction; ACTION_ROW: MessageComponentInteraction; + STRING_SELECT: SelectMenuInteraction; USER_SELECT: SelectMenuInteraction; ROLE_SELECT: SelectMenuInteraction; MENTIONABLE_SELECT: SelectMenuInteraction; @@ -1887,9 +1888,9 @@ export type MappedInteractionTypes = EnumValue typeof MessageComponentTypes, { BUTTON: ButtonInteraction>; - STRING_SELECT: SelectMenuInteraction>; ACTION_ROW: MessageComponentInteraction>; TEXT_INPUT: ModalSubmitInteraction>; + STRING_SELECT: SelectMenuInteraction>; USER_SELECT: SelectMenuInteraction>; ROLE_SELECT: SelectMenuInteraction>; MENTIONABLE_SELECT: SelectMenuInteraction>; @@ -2268,11 +2269,11 @@ export class MessageSelectMenu extends BaseMessageComponent { public minValues: number | null; public options: MessageSelectOption[]; public placeholder: string | null; - public type: SelectMenuTypes; + public type: SelectMenuComponentType; public channelTypes: ChannelTypes[]; public addOptions(...options: MessageSelectOptionData[] | MessageSelectOptionData[][]): this; public setOptions(...options: MessageSelectOptionData[] | MessageSelectOptionData[][]): this; - public setType(type: SelectMenuTypes): this; + public setType(type: SelectMenuComponentType | SelectMenuComponentTypes): this; public addChannelTypes(...channelTypes: ChannelTypes[]): this; public setChannelTypes(...channelTypes: ChannelTypes[]): this; public setCustomId(customId: string): this; @@ -2568,8 +2569,6 @@ export class Role extends Base { public static comparePositions(role1: Role, role2: Role): number; } -export type SelectMenuTypes = 'STRING_SELECT' | 'USER_SELECT' | 'ROLE_SELECT' | 'MENTIONABLE_SELECT' | 'CHANNEL_SELECT'; - export class SelectMenuInteraction extends MessageComponentInteraction { public constructor(client: Client, data: RawMessageSelectMenuInteractionData); public readonly component: CacheTypeReducer< @@ -2579,7 +2578,7 @@ export class SelectMenuInteraction extends MessageSelectMenu | APISelectMenuComponent, MessageSelectMenu | APISelectMenuComponent >; - public componentType: SelectMenuTypes; + public componentType: SelectMenuComponentType; public values: string[]; public inGuild(): this is SelectMenuInteraction<'raw' | 'cached'>; public inCachedGuild(): this is SelectMenuInteraction<'cached'>; @@ -3513,6 +3512,7 @@ export const Constants: { InteractionTypes: EnumHolder; InteractionResponseTypes: EnumHolder; MessageComponentTypes: EnumHolder; + SelectMenuComponentTypes: EnumHolder; MessageButtonStyles: EnumHolder; ModalComponentTypes: EnumHolder; TextInputStyles: EnumHolder; @@ -6292,14 +6292,34 @@ export interface MessageReference { export type MessageResolvable = Message | Snowflake; -export interface MessageSelectMenuOptions extends BaseMessageComponentOptions { - type?: SelectMenuTypes; +export interface BaseMessageSelectMenuOptions { + type?: SelectMenuComponentType | SelectMenuComponentTypes; customId?: string; disabled?: boolean; maxValues?: number; minValues?: number; placeholder?: string; } +export interface StringMessageSelectMenuOptions extends BaseMessageSelectMenuOptions { + type?: + | 'STRING_SELECT' + | SelectMenuComponentTypes.STRING_SELECT; + options?: MessageSelectOptionData[]; +} + +export interface ChannelMessageSelectMenuOptions extends BaseMessageSelectMenuOptions { + type?: 'CHANNEL_SELECT' | SelectMenuComponentTypes.CHANNEL_SELECT; + channelTypes?: ChannelTypes[]; +} + +export interface OtherMessageSelectMenuOptions extends BaseMessageSelectMenuOptions { + type?: ExcludeEnum; +} + +export type MessageSelectMenuOptions = + | StringMessageSelectMenuOptions + | ChannelMessageSelectMenuOptions + | OtherMessageSelectMenuOptions; export interface MessageSelectOption { default: boolean; @@ -6822,6 +6842,8 @@ export type VerificationLevel = keyof typeof VerificationLevels; export type VideoQualityMode = keyof typeof VideoQualityModes; +export type SelectMenuComponentType = keyof typeof SelectMenuComponentTypes; + export type VoiceBasedChannelTypes = VoiceBasedChannel['type']; export type VoiceChannelResolvable = Snowflake | VoiceChannel;