diff --git a/packages/builders/__tests__/components/actionRow.test.ts b/packages/builders/__tests__/components/actionRow.test.ts index 235259201930..d55d501f6ab8 100644 --- a/packages/builders/__tests__/components/actionRow.test.ts +++ b/packages/builders/__tests__/components/actionRow.test.ts @@ -5,7 +5,7 @@ describe('Action Row Components', () => { describe('Assertion Tests', () => { test('GIVEN valid components THEN do not throw', () => { expect(() => new ActionRow().addComponents(new ButtonComponent())).not.toThrowError(); - expect(() => new ActionRow().setComponents([new ButtonComponent()])).not.toThrowError(); + expect(() => new ActionRow().setComponents(new ButtonComponent())).not.toThrowError(); }); test('GIVEN valid JSON input THEN valid JSON output is given', () => { @@ -84,10 +84,10 @@ describe('Action Row Components', () => { .setCustomId('1234') .setMaxValues(10) .setMinValues(12) - .setOptions([ + .setOptions( new SelectMenuOption().setLabel('one').setValue('one'), new SelectMenuOption().setLabel('two').setValue('two'), - ]); + ); expect(new ActionRow().addComponents(button).toJSON()).toEqual(rowWithButtonData); expect(new ActionRow().addComponents(selectMenu).toJSON()).toEqual(rowWithSelectMenuData); diff --git a/packages/builders/__tests__/components/selectMenu.test.ts b/packages/builders/__tests__/components/selectMenu.test.ts index 0e00f6bcad58..102fc98784d3 100644 --- a/packages/builders/__tests__/components/selectMenu.test.ts +++ b/packages/builders/__tests__/components/selectMenu.test.ts @@ -23,7 +23,7 @@ describe('Button Components', () => { .setEmoji({ name: 'test' }) .setDescription('description'); expect(() => selectMenu().addOptions(option)).not.toThrowError(); - expect(() => selectMenu().setOptions([option])).not.toThrowError(); + expect(() => selectMenu().setOptions(option)).not.toThrowError(); }); test('GIVEN invalid inputs THEN Select Menu does throw', () => { diff --git a/packages/builders/__tests__/interactions/SlashCommands/Options.test.ts b/packages/builders/__tests__/interactions/SlashCommands/Options.test.ts index 9f89b78c3721..57d4a56f7e15 100644 --- a/packages/builders/__tests__/interactions/SlashCommands/Options.test.ts +++ b/packages/builders/__tests__/interactions/SlashCommands/Options.test.ts @@ -87,9 +87,7 @@ describe('Application Command toJSON() results', () => { min_value: 1, }); - expect( - getIntegerOption().setAutocomplete(true).setChoices([]).toJSON(), - ).toEqual({ + expect(getIntegerOption().setAutocomplete(true).setChoices().toJSON()).toEqual({ name: 'owo', description: 'Testing 123', type: ApplicationCommandOptionType.Integer, @@ -101,7 +99,9 @@ describe('Application Command toJSON() results', () => { choices: [], }); - expect(getIntegerOption().addChoice('uwu', 1).toJSON()).toEqual({ + expect( + getIntegerOption().addChoice({ name: 'uwu', value: 1 }).toJSON(), + ).toEqual({ name: 'owo', description: 'Testing 123', type: ApplicationCommandOptionType.Integer, @@ -131,7 +131,7 @@ describe('Application Command toJSON() results', () => { min_value: 1, }); - expect(getNumberOption().setAutocomplete(true).setChoices([]).toJSON()).toEqual({ + expect(getNumberOption().setAutocomplete(true).setChoices().toJSON()).toEqual({ name: 'owo', description: 'Testing 123', type: ApplicationCommandOptionType.Number, @@ -143,7 +143,7 @@ describe('Application Command toJSON() results', () => { choices: [], }); - expect(getNumberOption().addChoice('uwu', 1).toJSON()).toEqual({ + expect(getNumberOption().addChoice({ name: 'uwu', value: 1 }).toJSON()).toEqual({ name: 'owo', description: 'Testing 123', type: ApplicationCommandOptionType.Number, @@ -171,7 +171,7 @@ describe('Application Command toJSON() results', () => { required: true, }); - expect(getStringOption().setAutocomplete(true).setChoices([]).toJSON()).toEqual({ + expect(getStringOption().setAutocomplete(true).setChoices().toJSON()).toEqual({ name: 'owo', description: 'Testing 123', type: ApplicationCommandOptionType.String, @@ -181,7 +181,9 @@ describe('Application Command toJSON() results', () => { choices: [], }); - expect(getStringOption().addChoice('uwu', '1').toJSON()).toEqual({ + expect( + getStringOption().addChoice({ name: 'uwu', value: '1' }).toJSON(), + ).toEqual({ name: 'owo', description: 'Testing 123', type: ApplicationCommandOptionType.String, diff --git a/packages/builders/__tests__/interactions/SlashCommands/SlashCommands.test.ts b/packages/builders/__tests__/interactions/SlashCommands/SlashCommands.test.ts index 0f522b024c03..fc5534cba1ff 100644 --- a/packages/builders/__tests__/interactions/SlashCommands/SlashCommands.test.ts +++ b/packages/builders/__tests__/interactions/SlashCommands/SlashCommands.test.ts @@ -138,23 +138,23 @@ describe('Slash Commands', () => { integer .setName('iscool') .setDescription('Are we cool or what?') - .addChoices([['Very cool', 1_000]]), + .addChoices({ name: 'Very cool', value: 1_000 }), ) .addNumberOption((number) => number .setName('iscool') .setDescription('Are we cool or what?') - .addChoices([['Very cool', 1.5]]), + .addChoices({ name: 'Very cool', value: 1.5 }), ) .addStringOption((string) => string .setName('iscool') .setDescription('Are we cool or what?') - .addChoices([ - ['Fancy Pants', 'fp_1'], - ['Fancy Shoes', 'fs_1'], - ['The Whole shebang', 'all'], - ]), + .addChoices( + { name: 'Fancy Pants', value: 'fp_1' }, + { name: 'Fancy Shoes', value: 'fs_1' }, + { name: 'The Whole shebang', value: 'all' }, + ), ) .addIntegerOption((integer) => integer.setName('iscool').setDescription('Are we cool or what?').setAutocomplete(true), @@ -331,24 +331,24 @@ describe('Slash Commands', () => { expect(() => getBuilder().setName('foo').setDescription('foo').setDefaultPermission(false)).not.toThrowError(); }); - test('GIVEN an option that is autocompletable and has choices, THEN setting choices to an empty array should not throw an error', () => { + test('GIVEN an option that is autocompletable and has choices, THEN passing nothing to setChoices should not throw an error', () => { expect(() => - getBuilder().addStringOption(getStringOption().setAutocomplete(true).setChoices([])), + getBuilder().addStringOption(getStringOption().setAutocomplete(true).setChoices()), ).not.toThrowError(); }); test('GIVEN an option that is autocompletable, THEN setting choices should throw an error', () => { expect(() => getBuilder().addStringOption( - getStringOption() - .setAutocomplete(true) - .setChoices([['owo', 'uwu']]), + getStringOption().setAutocomplete(true).setChoices({ name: 'owo', value: 'uwu' }), ), ).toThrowError(); }); test('GIVEN an option, THEN setting choices should not throw an error', () => { - expect(() => getBuilder().addStringOption(getStringOption().setChoices([['owo', 'uwu']]))).not.toThrowError(); + expect(() => + getBuilder().addStringOption(getStringOption().setChoices({ name: 'owo', value: 'uwu' })), + ).not.toThrowError(); }); }); diff --git a/packages/builders/src/components/ActionRow.ts b/packages/builders/src/components/ActionRow.ts index a8a175b4c8f4..12cac4a21d04 100644 --- a/packages/builders/src/components/ActionRow.ts +++ b/packages/builders/src/components/ActionRow.ts @@ -34,7 +34,7 @@ export class ActionRow implem * Sets the components in this action row * @param components The components to set this row to */ - public setComponents(components: T[]) { + public setComponents(...components: T[]) { Reflect.set(this, 'components', [...components]); return this; } diff --git a/packages/builders/src/components/selectMenu/UnsafeSelectMenu.ts b/packages/builders/src/components/selectMenu/UnsafeSelectMenu.ts index 990f78ab47e6..67b847b245e5 100644 --- a/packages/builders/src/components/selectMenu/UnsafeSelectMenu.ts +++ b/packages/builders/src/components/selectMenu/UnsafeSelectMenu.ts @@ -84,7 +84,7 @@ export class UnsafeSelectMenuComponent implements Component { * Sets the options on this select menu * @param options The options to set on this select menu */ - public setOptions(options: SelectMenuOption[]) { + public setOptions(...options: SelectMenuOption[]) { Reflect.set(this, 'options', [...options]); return this; } diff --git a/packages/builders/src/interactions/slashCommands/mixins/ApplicationCommandOptionWithChoicesAndAutocompleteMixin.ts b/packages/builders/src/interactions/slashCommands/mixins/ApplicationCommandOptionWithChoicesAndAutocompleteMixin.ts index 786196fe6235..e6f954e0e2ab 100644 --- a/packages/builders/src/interactions/slashCommands/mixins/ApplicationCommandOptionWithChoicesAndAutocompleteMixin.ts +++ b/packages/builders/src/interactions/slashCommands/mixins/ApplicationCommandOptionWithChoicesAndAutocompleteMixin.ts @@ -4,7 +4,9 @@ import { validateMaxChoicesLength } from '../Assertions'; const stringPredicate = z.string().min(1).max(100); const numberPredicate = z.number().gt(-Infinity).lt(Infinity); -const choicesPredicate = z.tuple([stringPredicate, z.union([stringPredicate, numberPredicate])]).array(); +const choicesPredicate = z + .object({ name: stringPredicate, value: z.union([stringPredicate, numberPredicate]) }) + .array(); const booleanPredicate = z.boolean(); export class ApplicationCommandOptionWithChoicesAndAutocompleteMixin { @@ -17,10 +19,10 @@ export class ApplicationCommandOptionWithChoicesAndAutocompleteMixin): this { + const { name, value } = choice; if (this.autocomplete) { throw new RangeError('Autocomplete and choices are mutually exclusive to each other.'); } @@ -51,18 +53,18 @@ export class ApplicationCommandOptionWithChoicesAndAutocompleteMixin[]): this { if (this.autocomplete) { throw new RangeError('Autocomplete and choices are mutually exclusive to each other.'); } choicesPredicate.parse(choices); - for (const [label, value] of choices) this.addChoice(label, value); + for (const entry of choices) this.addChoice(entry); return this; } - public setChoices(choices: [name: string, value: T][]): this { + public setChoices[]>(...choices: Input): this { if (choices.length > 0 && this.autocomplete) { throw new RangeError('Autocomplete and choices are mutually exclusive to each other.'); } @@ -70,7 +72,7 @@ export class ApplicationCommandOptionWithChoicesAndAutocompleteMixin