@@ -21,10 +21,19 @@ export class CommandHelper {
2121
2222 Logger . info ( `Starting Command loading for ${ guildId } ....` . gray . italic )
2323
24+ // ADD /commands to GUILD
25+ await fetch ( `https://discord.com/api/v10/applications/${ client . user . id } /guilds/${ guildId } /commands` , {
26+ method : "POST" ,
27+ headers : {
28+ "Content-Type" : "application/json" ,
29+ Authorization : `Bot ${ Config . Bot . DiscordBotToken } `
30+ } ,
31+ body : JSON . stringify ( client . commands . get ( "commands" ) . command )
32+ } )
33+
2434 let cmdlist : any [ ] = [ ] ;
2535 const stats = {
2636 commands : 0 ,
27- userInstall : 0 ,
2837 contextMenus : 0 ,
2938 subCommands : 0 ,
3039 subCommandGroups : 0
@@ -51,7 +60,6 @@ export class CommandHelper {
5160 commands : moduleCommandFolder ,
5261 contextMenus : path . join ( modulesFolder , moduleDir , "contextmenu" ) ,
5362 subCommands : path . join ( moduleCommandFolder , "subCommand" ) ,
54- userInstall : path . join ( moduleCommandFolder , "userInstall" ) ,
5563 subCommandGroups : path . join ( moduleCommandFolder , "subCommandGroup" ) ,
5664 } ;
5765
@@ -67,8 +75,8 @@ export class CommandHelper {
6775
6876 try {
6977 const module = await import ( pathToFileURL ( filePath ) . href ) ;
70- if ( module . default ?. data ) {
71- cmdlist . push ( module . default . data . toJSON ( ) ) ;
78+ if ( module . default ?. command ) {
79+ cmdlist . push ( module . default . command . toJSON ( ) ) ;
7280 stats . commands ++ ;
7381 }
7482 } catch ( error ) {
@@ -83,8 +91,8 @@ export class CommandHelper {
8391 for ( const filePath of contextCommandFiles ) {
8492 try {
8593 const module = await import ( pathToFileURL ( filePath ) . href ) ;
86- if ( module . default ?. data ) {
87- cmdlist . push ( module . default . data . toJSON ( ) ) ;
94+ if ( module . default ?. command ) {
95+ cmdlist . push ( module . default . command . toJSON ( ) ) ;
8896 stats . contextMenus ++ ;
8997 }
9098 } catch ( error ) {
@@ -115,22 +123,45 @@ export class CommandHelper {
115123 }
116124 } )
117125
118- // TODO: ADD COMMAND_OVERWRITES
126+ if ( buildInCommandOverrides . length > 0 ) {
127+ cmdlist = cmdlist
128+ . filter ( cmd => {
129+ const override = buildInCommandOverrides . find ( o => o . CodeName === cmd . name ) ;
130+ return ! ( override && override . IsEnabled === false ) ;
131+ } )
132+ . map ( cmd => {
133+ const override = buildInCommandOverrides . find ( o => o . CodeName === cmd . name ) ;
134+ if ( override ) {
135+ return {
136+ ...cmd ,
137+ name : override . CustomName ,
138+ description : override . Description ?? client . commands . get ( override . CodeName ) . command . description ,
139+ default_member_permissions : override . Permissions ?? client . commands . get ( override . CodeName ) . command . default_member_permissions
140+ } ;
141+ }
142+ return cmd ;
143+ } )
144+ }
119145
120146 Logger . info ( `Sending commands to guild ${ guildId } for client ${ client . user . username } ` ) ;
121147
122148 try {
123- const commandReq = await fetch ( `https://discord.com/api/v10/applications/${ client . user . id } /guilds/${ guildId } /commands` , {
149+ await fetch ( `https://discord.com/api/v10/applications/${ client . user . id } /guilds/${ guildId } /commands` , {
150+ method : "PUT" ,
151+ headers : {
152+ "Content-Type" : "application/json" ,
153+ Authorization : `Bot ${ Config . Bot . DiscordBotToken } `
154+ } ,
155+ body : JSON . stringify ( [ ] )
156+ } )
157+ await fetch ( `https://discord.com/api/v10/applications/${ client . user . id } /guilds/${ guildId } /commands` , {
124158 method : "PUT" ,
125159 headers : {
126160 "Content-Type" : "application/json" ,
127161 Authorization : `Bot ${ Config . Bot . DiscordBotToken } `
128162 } ,
129163 body : JSON . stringify ( cmdlist )
130164 } )
131- const data = await commandReq . json ( )
132- console . log ( JSON . stringify ( data ) )
133-
134165 } catch ( e ) {
135166 Logger . error ( `Failed to load commands: ${ e } ` )
136167 }
@@ -192,11 +223,12 @@ export class CommandHelper {
192223 }
193224 }
194225 }
226+
195227 Logger . info ( {
196228 timestamp : new Date ( ) . toISOString ( ) ,
197229 level : "info" ,
198230 label : "CommandHelper" ,
199- message : `Discord added ${ cmdlist . length } commands (${ stats . subCommands } subCommands, ${ stats . subCommandGroups } subCommandGroups), ${ stats . userInstall } userInstall commands, ${ stats . contextMenus } context menu commands from ${ moduleDirectories . length } module(s) for ${ guildId } ` ,
231+ message : `Discord added ${ cmdlist . length } commands (${ stats . subCommands } subCommands, ${ stats . subCommandGroups } subCommandGroups), ${ stats . contextMenus } context menu commands from ${ moduleDirectories . length } module(s) for ${ guildId } ` ,
200232 botType : Config . BotType . toString ( ) || "Unknown" ,
201233 action : LoggingAction . Command ,
202234 } ) ;
@@ -250,8 +282,8 @@ export class CommandHelper {
250282
251283 try {
252284 const module = await import ( pathToFileURL ( filePath ) . href ) ;
253- if ( module . default ?. data ) {
254- cmdlist . push ( module . default . data . toJSON ( ) ) ;
285+ if ( module . default ?. command ) {
286+ cmdlist . push ( module . default . command . toJSON ( ) ) ;
255287 stats . commands ++ ;
256288 }
257289 } catch ( error ) {
@@ -266,8 +298,8 @@ export class CommandHelper {
266298 for ( const filePath of userCommandFiles ) {
267299 try {
268300 const module = await import ( pathToFileURL ( filePath ) . href ) ;
269- if ( module . default ?. data ) {
270- applicationcmdlist . push ( module . default . data . toJSON ( ) ) ;
301+ if ( module . default ?. command ) {
302+ applicationcmdlist . push ( module . default . command . toJSON ( ) ) ;
271303 stats . userInstall ++ ;
272304 }
273305 } catch ( error ) {
@@ -282,8 +314,8 @@ export class CommandHelper {
282314 for ( const filePath of contextCommandFiles ) {
283315 try {
284316 const module = await import ( pathToFileURL ( filePath ) . href ) ;
285- if ( module . default ?. data ) {
286- cmdlist . push ( module . default . data . toJSON ( ) ) ;
317+ if ( module . default ?. command ) {
318+ cmdlist . push ( module . default . command . toJSON ( ) ) ;
287319 stats . contextMenus ++ ;
288320 }
289321 } catch ( error ) {
@@ -350,7 +382,7 @@ export class CommandHelper {
350382 let successCount = 0 ;
351383 let errorCount = 0 ;
352384 const BATCH_SIZE = 5 ;
353- const DELAY_MS = 3000 ;
385+ const DELAY_MS = 3000 ;
354386
355387 for ( const guild of guildArray ) {
356388 try {
@@ -360,7 +392,7 @@ export class CommandHelper {
360392 } ) ;
361393 await delay ( DELAY_MS ) ;
362394 }
363-
395+
364396 await CommandHelper . loadCommandsForGuild ( client , guild . id ) ;
365397 successCount ++ ;
366398
0 commit comments