diff --git a/packages/builders/__tests__/components/selectMenu.test.ts b/packages/builders/__tests__/components/selectMenu.test.ts index 6e0c887dc274..3c4d1997de42 100644 --- a/packages/builders/__tests__/components/selectMenu.test.ts +++ b/packages/builders/__tests__/components/selectMenu.test.ts @@ -6,6 +6,10 @@ const selectMenu = () => new StringSelectMenuBuilder(); const selectMenuOption = () => new StringSelectMenuOptionBuilder(); const longStr = 'a'.repeat(256); +const selectMenuOptionLabelAtLimit = 'a'.repeat(100); +const selectMenuOptionLabelAboveLimit = 'a'.repeat(101); +const selectMenuOptionValueAboveLimit = 'a'.repeat(101); +const selectMenuOptionDescriptionAboveLimit = 'a'.repeat(101); const selectMenuOptionData: APISelectMenuOption = { label: 'test', @@ -53,12 +57,12 @@ describe('Select Menu Components', () => { expect(() => selectMenu().setDisabled()).not.toThrowError(); expect(() => selectMenu().setPlaceholder('description')).not.toThrowError(); const option = selectMenuOption() - .setLabel('test') + .setLabel(selectMenuOptionLabelAtLimit) .setValue('test') .setDefault(true) .setEmoji({ name: 'test' }) .setDescription('description'); - expect(() => selectMenu().addOptions(option)).not.toThrowError(); + expect(() => selectMenu().setCustomId('customId').addOptions(option).toJSON()).not.toThrowError(); expect(() => selectMenu().setOptions(option)).not.toThrowError(); expect(() => selectMenu().setOptions({ label: 'test', value: 'test' })).not.toThrowError(); expect(() => selectMenu().addOptions([option])).not.toThrowError(); @@ -156,13 +160,13 @@ describe('Select Menu Components', () => { expect(() => { selectMenuOption() - .setLabel(longStr) - .setValue(longStr) + .setLabel(selectMenuOptionLabelAboveLimit) + .setValue(selectMenuOptionValueAboveLimit) // @ts-expect-error: Invalid default value .setDefault(-1) // @ts-expect-error: Invalid emoji .setEmoji({ name: 1 }) - .setDescription(longStr); + .setDescription(selectMenuOptionDescriptionAboveLimit); }).toThrowError(); }); diff --git a/packages/builders/src/components/Assertions.ts b/packages/builders/src/components/Assertions.ts index 7165a5dd6850..c7fb828837a0 100644 --- a/packages/builders/src/components/Assertions.ts +++ b/packages/builders/src/components/Assertions.ts @@ -50,6 +50,9 @@ export const labelValueDescriptionValidator = s .lengthLessThanOrEqual(100) .setValidationEnabled(isValidationEnabled); +/** + * @deprecated Replaced with selectMenuStringOptionPredicate. + */ export const jsonOptionValidator = s .object({ label: labelValueDescriptionValidator, diff --git a/packages/builders/src/components/selectMenu/Assertions.ts b/packages/builders/src/components/selectMenu/Assertions.ts index 8aa0c0f1df80..e26b671fe5dd 100644 --- a/packages/builders/src/components/selectMenu/Assertions.ts +++ b/packages/builders/src/components/selectMenu/Assertions.ts @@ -2,7 +2,6 @@ import { Result, s } from '@sapphire/shapeshift'; import { ChannelType, ComponentType, SelectMenuDefaultValueType } from 'discord-api-types/v10'; import { isValidationEnabled } from '../../util/validation.js'; import { customIdValidator, emojiValidator, idValidator } from '../Assertions.js'; -import { labelValidator } from '../textInput/Assertions.js'; const selectMenuBasePredicate = s.object({ id: idValidator.optional(), @@ -63,7 +62,7 @@ export const selectMenuUserPredicate = selectMenuBasePredicate export const selectMenuStringOptionPredicate = s .object({ - label: labelValidator, + label: s.string().lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100), value: s.string().lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100), description: s.string().lengthGreaterThanOrEqual(1).lengthLessThanOrEqual(100).optional(), emoji: emojiValidator.optional(), diff --git a/packages/builders/src/components/selectMenu/StringSelectMenu.ts b/packages/builders/src/components/selectMenu/StringSelectMenu.ts index 9c6542387db0..f3883e3d4c6f 100644 --- a/packages/builders/src/components/selectMenu/StringSelectMenu.ts +++ b/packages/builders/src/components/selectMenu/StringSelectMenu.ts @@ -1,7 +1,8 @@ import { ComponentType } from 'discord-api-types/v10'; import type { APIStringSelectComponent, APISelectMenuOption } from 'discord-api-types/v10'; import { normalizeArray, type RestOrArray } from '../../util/normalizeArray.js'; -import { jsonOptionValidator, optionsLengthValidator, validateRequiredSelectMenuParameters } from '../Assertions.js'; +import { optionsLengthValidator, validateRequiredSelectMenuParameters } from '../Assertions.js'; +import { selectMenuStringOptionPredicate } from './Assertions.js'; import { BaseSelectMenuBuilder } from './BaseSelectMenu.js'; import { StringSelectMenuOptionBuilder } from './StringSelectMenuOption.js'; @@ -63,7 +64,7 @@ export class StringSelectMenuBuilder extends BaseSelectMenuBuilder normalizedOption instanceof StringSelectMenuOptionBuilder ? normalizedOption - : new StringSelectMenuOptionBuilder(jsonOptionValidator.parse(normalizedOption)), + : new StringSelectMenuOptionBuilder(selectMenuStringOptionPredicate.parse(normalizedOption)), ), ); return this; @@ -120,7 +121,7 @@ export class StringSelectMenuBuilder extends BaseSelectMenuBuilder normalizedOption instanceof StringSelectMenuOptionBuilder ? normalizedOption - : new StringSelectMenuOptionBuilder(jsonOptionValidator.parse(normalizedOption)), + : new StringSelectMenuOptionBuilder(selectMenuStringOptionPredicate.parse(normalizedOption)), ), ); diff --git a/packages/builders/src/index.ts b/packages/builders/src/index.ts index 3fe81285e328..77f8fc7922b0 100644 --- a/packages/builders/src/index.ts +++ b/packages/builders/src/index.ts @@ -31,6 +31,7 @@ export { */ StringSelectMenuOptionBuilder as SelectMenuOptionBuilder, } from './components/selectMenu/StringSelectMenuOption.js'; +export * as SelectMenuAssertions from './components/selectMenu/Assertions.js'; export * from './components/selectMenu/StringSelectMenuOption.js'; export * from './components/selectMenu/UserSelectMenu.js';