1
- import { Client , Collection , CommandInteractionOptionResolver , Guild , Message , TextChannel , User } from 'discord.js' ;
1
+ import { Client , Collection , CommandInteractionOptionResolver , Guild , Message , MessageActionRow , MessageSelectMenu , SelectMenuInteraction , TextChannel , User } from 'discord.js' ;
2
2
import type { GClient } from '../lib/GClient' ;
3
3
import { CommandContext } from '../lib/structures/contexts/CommandContext' ;
4
4
import { CommandType } from '../lib/structures/Command' ;
@@ -13,10 +13,38 @@ const cooldowns = new Collection<string, Collection<string, number>>();
13
13
14
14
const checkValidation = async ( arg : MessageArgumentTypes , content : string , client : Client , guild : Guild , argument : Argument , channel : TextChannel , user : User ) => {
15
15
if ( ! content ) {
16
- channel . send ( `${ user . toString ( ) } , please define argument \`${ argument . name } \`, type: ${ Util . toPascalCase ( ArgumentType [ argument . type . toString ( ) ] ) } ` ) ;
17
- const message = await channel . awaitMessages ( { filter : ( m ) => m . author . id === user . id && m . channelId === channel . id , time : 60000 , max : 1 } ) ;
16
+ const text = `${ user . toString ( ) } , please define argument \`${ argument . name } \`, type: ${ Util . toPascalCase ( ArgumentType [ argument . type . toString ( ) ] ) } `
17
+ if ( argument . type === ArgumentType . STRING && argument . choices ?. length !== 0 ) {
18
+ const menu = new MessageSelectMenu ( )
19
+ . setCustomId ( 'argument_choices' )
20
+ . setMaxValues ( 1 )
21
+ . setMinValues ( 0 )
22
+ . setPlaceholder ( 'Select a choice' ) ;
18
23
19
- content = [ ...message . values ( ) ] ?. [ 0 ] ?. content ;
24
+ menu . setOptions (
25
+ argument . choices . map (
26
+ ch => ( {
27
+ label : ch . name ,
28
+ value : ch . value
29
+ } )
30
+ )
31
+ ) ;
32
+
33
+ const message = await channel . send ( {
34
+ content : text ,
35
+ components : [ new MessageActionRow ( ) . addComponents ( menu ) ]
36
+ } ) ;
37
+
38
+ const component : SelectMenuInteraction = await channel . awaitMessageComponent ( { filter : ( m ) => m . componentType === 'SELECT_MENU' && m . user . id === user . id && m . channelId === channel . id && m . message . id === message . id && m . customId === 'argument_choices' , time : 60000 } ) as SelectMenuInteraction ;
39
+
40
+ component . deferUpdate ( ) ;
41
+ content = component . values ?. [ 0 ] ;
42
+ } else {
43
+ channel . send ( text ) ;
44
+ const message = await channel . awaitMessages ( { filter : ( m ) => m . author . id === user . id && m . channelId === channel . id , time : 60000 , max : 1 } ) ;
45
+
46
+ content = [ ...message . values ( ) ] ?. [ 0 ] ?. content ;
47
+ }
20
48
}
21
49
22
50
const validate = arg . validate ( content ) ;
0 commit comments