1
+ const { MessageEmbed, MessageActionRow, MessageSelectMenu } = require ( 'discord.js' ) ;
2
+ const humanizeDuration = require ( "humanize-duration" ) ;
3
+
4
+ module . exports = {
5
+ name : "help" ,
6
+ description : "Get list of all bot commands" ,
7
+ options : [
8
+ {
9
+ name : "command" ,
10
+ description : "Command you need help for" ,
11
+ type : 3
12
+ }
13
+ ] ,
14
+ usage : "/ping" ,
15
+ category : "info" ,
16
+ run : async ( interaction , client ) => {
17
+ try {
18
+ const command = interaction . options . getString ( 'command' ) ;
19
+ if ( command ) {
20
+ const cmd = client . commands . get ( command . toLowerCase ( ) ) ;
21
+ if ( ! cmd ) {
22
+ return interaction . reply ( { content : `I can\'t find \`${ cmd } \` command` , ephemeral : true } )
23
+ }
24
+ const embed = new MessageEmbed ( )
25
+ . setColor ( interaction . guild . me . displayHexColor )
26
+ if ( cmd . name ) {
27
+ embed . setTitle ( `Command: ${ cmd . name } ` )
28
+ }
29
+ if ( cmd . description ) {
30
+ embed . setDescription ( cmd . description )
31
+ }
32
+ if ( cmd . usage ) {
33
+ embed . addField ( 'Usage:' , cmd . usage )
34
+ }
35
+ if ( cmd . timeout ) {
36
+ embed . addField ( 'Timeout:' , humanizeDuration ( cmd . timeout , { round : true } ) )
37
+ }
38
+ return interaction . reply ( { embeds : [ embed ] } )
39
+ }
40
+ const row = new MessageActionRow ( )
41
+ . addComponents (
42
+ new MessageSelectMenu ( )
43
+ . setCustomId ( 'help_menu' )
44
+ . setPlaceholder ( 'Select Command Category.' )
45
+ . setMinValues ( 1 )
46
+ . setMaxValues ( 1 )
47
+ . addOptions ( [
48
+ {
49
+ label : "General" ,
50
+ emoji : "⚙" ,
51
+ description : "Show all commands in general category." ,
52
+ value : "general"
53
+ } ,
54
+ {
55
+ label : "Info" ,
56
+ description : "Show all commands in info category." ,
57
+ emoji : "ℹ" ,
58
+ value : "info"
59
+ }
60
+ ] )
61
+ )
62
+ interaction . reply ( { content : "**👋 Select Category You Need Help For**" , components : [ row ] } ) ;
63
+ const filter = i => i . customId === 'help_menu' || 'selected_command' && i . user . id === interaction . user . id ;
64
+ const collector = interaction . channel . createMessageComponentCollector ( { filter : filter , max : 2 , componentType : "SELECT_MENU" } ) ;
65
+ collector . on ( 'collect' , async i => {
66
+ if ( i . values . includes ( 'general' ) ) {
67
+ await i . deferUpdate ( ) ;
68
+ const loopArray = [ ] ;
69
+ if ( client . commands . filter ( r => r . category === 'general' ) . size === '25' ) {
70
+ loopArray . slice ( 0 , 25 )
71
+ }
72
+ client . commands . filter ( r => r . category === "general" ) . forEach ( cmd => {
73
+ loopArray . push ( {
74
+ label : cmd . name ,
75
+ value : cmd . name ,
76
+ description : cmd . description ,
77
+ emoji : "⚙"
78
+ } )
79
+ } )
80
+ const commandRow = row . setComponents (
81
+ new MessageSelectMenu ( )
82
+ . setCustomId ( 'general_cmd' )
83
+ . setPlaceholder ( 'General Commands' )
84
+ . setMinValues ( 1 )
85
+ . setMaxValues ( 1 )
86
+ . addOptions ( loopArray )
87
+ )
88
+ return i . editReply ( {
89
+ content : "**Select what command you need help for.**" ,
90
+ components : [ commandRow ]
91
+ } )
92
+ }
93
+ if ( i . values . includes ( 'info' ) ) {
94
+ await i . deferUpdate ( ) ;
95
+ const loopArray = [ ] ;
96
+ if ( client . commands . filter ( r => r . category === 'info' ) . size === '25' ) {
97
+ loopArray . slice ( 0 , 25 )
98
+ }
99
+ client . commands . filter ( r => r . category === "info" ) . forEach ( cmd => {
100
+ loopArray . push ( {
101
+ label : cmd . name ,
102
+ value : cmd . name ,
103
+ description : cmd . description ,
104
+ emoji : "ℹ"
105
+ } )
106
+ } )
107
+ const commandRow = row . setComponents (
108
+ new MessageSelectMenu ( )
109
+ . setCustomId ( 'info_cmd' )
110
+ . setPlaceholder ( 'Info Commands' )
111
+ . setMinValues ( 1 )
112
+ . setMaxValues ( 1 )
113
+ . addOptions ( loopArray )
114
+ )
115
+ return i . editReply ( {
116
+ content : "**Select what command you need help for.**" ,
117
+ components : [ commandRow ]
118
+ } )
119
+ }
120
+ } )
121
+ } catch ( e ) {
122
+ return false ;
123
+ }
124
+ }
125
+ }
0 commit comments