11import { readdirSync } from 'fs' ;
2+ import chalk from 'chalk' ;
23
34async function loadCommands ( client ) {
4- const commandFiles = readdirSync ( './src/commands' ) . filter ( file => file . endsWith ( '.js' ) ) ;
5- for ( let i = 0 ; i < commandFiles . length ; i ++ ) {
6- const cmd = await import ( `../commands/${ commandFiles [ i ] } ` ) ;
7- client . commands . set ( cmd . default . name , cmd . default ) ;
5+ const commandFiles = readdirSync ( './src/commands' ) . filter ( file => file . endsWith ( '.js' ) ) ;
6+ for ( let i = 0 ; i < commandFiles . length ; i ++ ) {
7+ const cmd = await import ( `../commands/${ commandFiles [ i ] } ` ) ;
8+ client . commands . set ( cmd . default . name , cmd . default ) ;
9+ console . log ( chalk . greenBright ( `[COMMAND] Loaded ${ ( chalk . yellow ( commandFiles [ i ] ) ) } with command ${ ( chalk . yellow ( cmd . default . name ) ) } ${ ( chalk . yellow ( `[${ cmd . default . aliases } ]` ) ) } ` ) ) ;
810
9- if ( cmd . default . aliases ) {
10- cmd . default . aliases . forEach ( alias => {
11- client . aliases . set ( alias , cmd . default ) ;
12- } ) ;
13- } ;
14- }
11+ if ( cmd . default . aliases ) {
12+ cmd . default . aliases . forEach ( alias => {
13+ client . aliases . set ( alias , cmd . default ) ;
14+ } ) ;
15+ }
16+ }
1517}
1618
17- export default { loadCommands } ;
19+ async function reloadCommands ( client ) {
20+ client . commands . clear ( ) ;
21+ client . aliases . clear ( ) ;
22+ const commandFiles = readdirSync ( './src/commands' ) . filter ( file => file . endsWith ( '.js' ) ) ;
23+ for ( let i = 0 ; i < commandFiles . length ; i ++ ) {
24+ const cmd = await import ( `../commands/${ commandFiles [ i ] } ` ) ;
25+ client . commands . set ( cmd . default . name , cmd . default ) ;
26+ console . log ( chalk . greenBright ( `[COMMAND] Reloaded ${ ( chalk . yellow ( commandFiles [ i ] ) ) } with command ${ ( chalk . yellow ( cmd . default . name ) ) } ${ ( chalk . yellow ( `[${ cmd . default . aliases } ]` ) ) } ` ) ) ;
27+
28+ if ( cmd . default . aliases ) {
29+ cmd . default . aliases . forEach ( alias => {
30+ client . aliases . set ( alias , cmd . default ) ;
31+ } ) ;
32+ }
33+ }
34+ return commandFiles . length ;
35+ }
36+
37+ export default { loadCommands, reloadCommands } ;
0 commit comments