Skip to content

Commit fe10d0b

Browse files
committed
fix: button labels
1 parent 2475890 commit fe10d0b

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

packages/builders/__tests__/components/selectMenu.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ const selectMenuWithId = () => new StringSelectMenuBuilder({ custom_id: 'hi' });
77
const selectMenuOption = () => new StringSelectMenuOptionBuilder();
88

99
const longStr = 'a'.repeat(256);
10+
const selectMenuOptionLabelAboveLimit = 'a'.repeat(101);
11+
const selectMenuOptionValueAboveLimit = 'a'.repeat(101);
12+
const selectMenuOptionDescriptionAboveLimit = 'a'.repeat(101);
1013

1114
const selectMenuOptionData: APISelectMenuOption = {
1215
label: 'test',
@@ -196,13 +199,13 @@ describe('Select Menu Components', () => {
196199

197200
expect(() => {
198201
selectMenuOption()
199-
.setLabel(longStr)
200-
.setValue(longStr)
202+
.setLabel(selectMenuOptionLabelAboveLimit)
203+
.setValue(selectMenuOptionValueAboveLimit)
201204
// @ts-expect-error: Invalid default value
202205
.setDefault(-1)
203206
// @ts-expect-error: Invalid emoji
204207
.setEmoji({ name: 1 })
205-
.setDescription(longStr)
208+
.setDescription(selectMenuOptionDescriptionAboveLimit)
206209
.toJSON();
207210
}).toThrowError();
208211
});

packages/builders/src/components/Assertions.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import { ButtonStyle, ChannelType, ComponentType, SelectMenuDefaultValueType } f
22
import { z } from 'zod';
33
import { idPredicate, customIdPredicate } from '../Assertions.js';
44

5-
const labelPredicate = z.string().min(1).max(80);
6-
75
export const emojiPredicate = z
86
.strictObject({
97
id: z.string().optional(),
@@ -19,11 +17,13 @@ const buttonPredicateBase = z.strictObject({
1917
disabled: z.boolean().optional(),
2018
});
2119

20+
const buttonLabelPredicate = z.string().min(1).max(80);
21+
2222
const buttonCustomIdPredicateBase = buttonPredicateBase
2323
.extend({
2424
custom_id: customIdPredicate,
2525
emoji: emojiPredicate.optional(),
26-
label: z.string().min(1).max(80).optional(),
26+
label: buttonLabelPredicate.optional(),
2727
})
2828
.refine((data) => data.emoji !== undefined || data.label !== undefined, {
2929
message: 'Buttons with a custom id must have either an emoji or a label.',
@@ -38,7 +38,7 @@ const buttonLinkPredicate = buttonPredicateBase.extend({
3838
style: z.literal(ButtonStyle.Link),
3939
url: z.url({ protocol: /^(?:https?|discord)$/ }).max(512),
4040
emoji: emojiPredicate.optional(),
41-
label: labelPredicate,
41+
label: buttonLabelPredicate.optional(),
4242
});
4343

4444
const buttonPremiumPredicate = buttonPredicateBase.extend({
@@ -96,7 +96,7 @@ export const selectMenuRolePredicate = selectMenuBasePredicate.extend({
9696
});
9797

9898
export const selectMenuStringOptionPredicate = z.object({
99-
label: labelPredicate,
99+
label: z.string().min(1).max(100),
100100
value: z.string().min(1).max(100),
101101
description: z.string().min(1).max(100).optional(),
102102
emoji: emojiPredicate.optional(),

0 commit comments

Comments
 (0)