11import {
2- ChatInputCommandInteraction
2+ ChatInputCommandInteraction ,
3+ AutocompleteInteraction
34} from 'discord.js' ;
45
56import type {
@@ -11,13 +12,16 @@ import type {
1112 BaseCommand ,
1213 BaseCommandList ,
1314 CommandWithOptions ,
15+ CommandHasSubcommands ,
1416 TypedCommandOptionsResolver ,
1517 TypedCommandOptionsNeverResolver ,
18+ TypedAutocompleteOptionsResolver ,
19+ TypedAutocompleteOptionsNeverResolver ,
1620 PickBaseCommandByName ,
1721 ExtractCommandSubcommands ,
1822 ExtractCommandBasicOptions ,
1923 ExtractSubcommandBasicOptions ,
20- CommandHasSubcommands
24+ AutocompleteCommands
2125} from './index.js' ;
2226
2327export declare class TypedCommandOptions <
@@ -38,6 +42,24 @@ export declare class TypedCommandSubcommandOptions<
3842 public options : TypedCommandOptionsResolver < ExtractSubcommandBasicOptions < CommandWithOptions < T > [ 'options' ] , K > > ;
3943}
4044
45+ export declare class TypedAutocompleteCommandOptions <
46+ T extends BaseCommand
47+ > extends AutocompleteInteraction < CacheType > {
48+ public commandName : T [ 'name' ] ;
49+ public options : CommandHasSubcommands < CommandWithOptions < T > [ 'options' ] > extends true
50+ ? TypedAutocompleteOptionsNeverResolver < ExtractCommandBasicOptions < CommandWithOptions < T > [ 'options' ] > >
51+ : TypedAutocompleteOptionsResolver < ExtractCommandBasicOptions < CommandWithOptions < T > [ 'options' ] > > ;
52+ }
53+
54+ export declare class TypedAutocompleteSubcommandOptions <
55+ T extends BaseCommand ,
56+ K extends ExtractCommandSubcommands < CommandWithOptions < T > [ 'options' ] > [ 'name' ]
57+ > extends AutocompleteInteraction < CacheType > {
58+ private subcommandName : K ;
59+ public commandName : T [ 'name' ] ;
60+ public options : TypedAutocompleteOptionsResolver < ExtractSubcommandBasicOptions < CommandWithOptions < T > [ 'options' ] , K > > ;
61+ }
62+
4163// eslint-disable-next-line @typescript-eslint/no-unused-vars
4264export function typed < T extends BaseCommandList = BaseCommandList > ( commandList : T ) {
4365 function command <
@@ -55,9 +77,28 @@ export function typed<T extends BaseCommandList = BaseCommandList>(commandList:
5577 return ( interaction as TypedSubcommand < T , K , S > ) . options . getSubcommand ( ) === name ;
5678 }
5779
80+ function autocomplete <
81+ A extends AutocompleteCommands < T > ,
82+ K extends A [ number ] [ 'name' ]
83+ >
84+ ( interaction : Interaction , name : K ) : interaction is TypedAutocompleteCommand < A , K > {
85+ return interaction . isAutocomplete ( ) && interaction . commandName === name ;
86+ }
87+
88+ function autocompleteSubcommand <
89+ A extends AutocompleteCommands < T > ,
90+ K extends A [ number ] [ 'name' ] ,
91+ S extends ExtractCommandSubcommands < CommandWithOptions < PickBaseCommandByName < A , K > > [ 'options' ] > [ 'name' ]
92+ >
93+ ( interaction : TypedAutocompleteCommand < A , K > , name : S ) : interaction is TypedAutocompleteSubcommand < A , K , S > {
94+ return ( interaction as TypedAutocompleteSubcommand < A , K , S > ) . options . getSubcommand ( ) === name ;
95+ }
96+
5897 return {
5998 command,
60- subcommand
99+ subcommand,
100+ autocomplete,
101+ autocompleteSubcommand
61102 } ;
62103}
63104
@@ -71,3 +112,14 @@ export type TypedSubcommand<
71112 K extends T [ number ] [ 'name' ] ,
72113 S extends ExtractCommandSubcommands < CommandWithOptions < PickBaseCommandByName < T , K > > [ 'options' ] > [ 'name' ]
73114> = TypedCommandSubcommandOptions < PickBaseCommandByName < T , K > , S > ;
115+
116+ export type TypedAutocompleteCommand <
117+ T extends BaseCommandList ,
118+ K extends T [ number ] [ 'name' ]
119+ > = TypedAutocompleteCommandOptions < PickBaseCommandByName < T , K > > ;
120+
121+ export type TypedAutocompleteSubcommand <
122+ T extends BaseCommandList ,
123+ K extends T [ number ] [ 'name' ] ,
124+ S extends ExtractCommandSubcommands < CommandWithOptions < PickBaseCommandByName < T , K > > [ 'options' ] > [ 'name' ]
125+ > = TypedAutocompleteSubcommandOptions < PickBaseCommandByName < T , K > , S > ;
0 commit comments