1- import { Client , IntentsBitField , REST , SlashCommandBuilder , Routes , SlashCommandSubcommandBuilder , RESTPostAPIApplicationCommandsJSONBody } from "discord.js" ;
1+ import { Client , IntentsBitField , REST , SlashCommandBuilder , Routes , SlashCommandSubcommandBuilder , RESTPostAPIApplicationCommandsJSONBody , Collection } from "discord.js" ;
22import fs from 'fs' ;
33import knex , { Knex } from "knex" ;
44import toml from 'toml' ;
@@ -76,12 +76,12 @@ class DBot extends Client {
7676 }
7777
7878 commands = {
79- list : [ ] as RESTPostAPIApplicationCommandsJSONBody [ ] ,
79+ list : new Collection < any , any > ( ) ,
8080
8181 parse : async ( ) => {
8282 const folderPath = join ( __dirname , 'commands' ) ;
8383 const commandCategories = fs . readdirSync ( folderPath ) ;
84- const commands = [ ] ;
84+ const commands = new Collection < string , SlashCommand > ( ) ;
8585
8686 for ( const category of commandCategories ) {
8787 const commandsPath = join ( folderPath , category ) ;
@@ -92,22 +92,29 @@ class DBot extends Client {
9292 const commandClass = ( await import ( `file://${ filePath } ` ) ) . default ;
9393 const command : SlashCommand = new commandClass ( this . kogBot ) ;
9494
95- commands . push ( command . data . toJSON ( ) ) ;
95+ commands . set ( command . data . name , command ) ;
9696 }
9797 }
9898 return commands ;
9999 } ,
100100
101101 deploy : async ( ) => {
102- this . commands . list = await this . commands . parse ( ) ;
102+ const parsed = await this . commands . parse ( ) ;
103+ this . commands . list = parsed ;
104+ const JSONCommands : RESTPostAPIApplicationCommandsJSONBody [ ] = [ ] ;
105+
106+ this . commands . list . forEach ( ( command ) => {
107+ JSONCommands . push ( command . data . toJSON ( ) ) ;
108+ } ) ;
109+
103110 if ( process . argv . includes ( '--ci' ) ) {
104111 console . log ( "Not deploying commands because of CI environment. Commands successfully parsed!" )
105112 process . exit ( 0 )
106113 }
107- console . log ( `Deploying ${ this . commands . list . length } commands...` ) ;
114+ console . log ( `Deploying ${ this . commands . list . size } commands...` ) ;
108115 await this . REST . put (
109116 Routes . applicationCommands ( this . kogBot . environment . discord . client_id ) ,
110- { body : [ ] }
117+ { body : JSONCommands }
111118 ) ;
112119 }
113120 }
0 commit comments