Skip to content

Commit 46f8f3c

Browse files
committed
fix: allow subcommand with groups
1 parent 02fc101 commit 46f8f3c

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

packages/builders/__tests__/interactions/ChatInputCommands/ChatInputCommands.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,29 @@ describe('ChatInput Commands', () => {
376376
});
377377
});
378378

379+
describe('Subcommand builder and subcommand group builder', () => {
380+
test('GIVEN both types THEN does not throw error', () => {
381+
expect(() =>
382+
getBuilder()
383+
.setName('test')
384+
.setDescription('Test command')
385+
.addSubcommands((subcommand) =>
386+
subcommand.setName('subcommand').setDescription('Description of subcommand'),
387+
)
388+
.addSubcommandGroups((subcommandGroup) =>
389+
subcommandGroup
390+
.setName('group')
391+
.setDescription('Description of group')
392+
393+
.addSubcommands((subcommand) =>
394+
subcommand.setName('subcommand').setDescription('Description of group subcommand'),
395+
),
396+
)
397+
.toJSON(),
398+
).not.toThrowError();
399+
});
400+
});
401+
379402
describe('ChatInput command localizations', () => {
380403
const expectedSingleLocale = { [Locale.EnglishUS]: 'foobar' };
381404
const expectedMultipleLocales = {

packages/builders/src/interactions/commands/chatInput/Assertions.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,14 @@ const baseChatInputCommandPredicate = sharedNameAndDescriptionPredicate.extend({
127127
// Because you can only add options via builders, there's no need to validate whole objects here otherwise
128128
const chatInputCommandOptionsPredicate = z.union([
129129
z.object({ type: basicOptionTypesPredicate }).array(),
130-
z.object({ type: z.literal(ApplicationCommandOptionType.Subcommand) }).array(),
131-
z.object({ type: z.literal(ApplicationCommandOptionType.SubcommandGroup) }).array(),
130+
z
131+
.object({
132+
type: z.union([
133+
z.literal(ApplicationCommandOptionType.Subcommand),
134+
z.literal(ApplicationCommandOptionType.SubcommandGroup),
135+
]),
136+
})
137+
.array(),
132138
]);
133139

134140
export const chatInputCommandPredicate = baseChatInputCommandPredicate.extend({

0 commit comments

Comments
 (0)