From 46f8f3c516a852236f424ac00319ff9524e55e3e Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Tue, 25 Nov 2025 21:42:27 +0000 Subject: [PATCH] fix: allow subcommand with groups --- .../ChatInputCommands.test.ts | 23 +++++++++++++++++++ .../commands/chatInput/Assertions.ts | 10 ++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/packages/builders/__tests__/interactions/ChatInputCommands/ChatInputCommands.test.ts b/packages/builders/__tests__/interactions/ChatInputCommands/ChatInputCommands.test.ts index 0affe76c8b8a..154fbf288d7a 100644 --- a/packages/builders/__tests__/interactions/ChatInputCommands/ChatInputCommands.test.ts +++ b/packages/builders/__tests__/interactions/ChatInputCommands/ChatInputCommands.test.ts @@ -376,6 +376,29 @@ describe('ChatInput Commands', () => { }); }); + describe('Subcommand builder and subcommand group builder', () => { + test('GIVEN both types THEN does not throw error', () => { + expect(() => + getBuilder() + .setName('test') + .setDescription('Test command') + .addSubcommands((subcommand) => + subcommand.setName('subcommand').setDescription('Description of subcommand'), + ) + .addSubcommandGroups((subcommandGroup) => + subcommandGroup + .setName('group') + .setDescription('Description of group') + + .addSubcommands((subcommand) => + subcommand.setName('subcommand').setDescription('Description of group subcommand'), + ), + ) + .toJSON(), + ).not.toThrowError(); + }); + }); + describe('ChatInput command localizations', () => { const expectedSingleLocale = { [Locale.EnglishUS]: 'foobar' }; const expectedMultipleLocales = { diff --git a/packages/builders/src/interactions/commands/chatInput/Assertions.ts b/packages/builders/src/interactions/commands/chatInput/Assertions.ts index 8d16afd8ac44..567ee6eb3762 100644 --- a/packages/builders/src/interactions/commands/chatInput/Assertions.ts +++ b/packages/builders/src/interactions/commands/chatInput/Assertions.ts @@ -127,8 +127,14 @@ const baseChatInputCommandPredicate = sharedNameAndDescriptionPredicate.extend({ // Because you can only add options via builders, there's no need to validate whole objects here otherwise const chatInputCommandOptionsPredicate = z.union([ z.object({ type: basicOptionTypesPredicate }).array(), - z.object({ type: z.literal(ApplicationCommandOptionType.Subcommand) }).array(), - z.object({ type: z.literal(ApplicationCommandOptionType.SubcommandGroup) }).array(), + z + .object({ + type: z.union([ + z.literal(ApplicationCommandOptionType.Subcommand), + z.literal(ApplicationCommandOptionType.SubcommandGroup), + ]), + }) + .array(), ]); export const chatInputCommandPredicate = baseChatInputCommandPredicate.extend({