@@ -16,53 +16,61 @@ client.commands = new Collection();
1616client . cooldowns = new Collection ( ) ;
1717
1818function loadEvents ( ) {
19- const eventsPath = path . join ( __dirname , "events" ) ;
20- const eventFiles = fs
21- . readdirSync ( eventsPath )
22- . filter ( ( file ) => file . endsWith ( ".js" ) ) ;
19+ try {
20+ const eventsPath = path . join ( __dirname , "events" ) ;
21+ const eventFiles = fs
22+ . readdirSync ( eventsPath )
23+ . filter ( ( file ) => file . endsWith ( ".js" ) ) ;
2324
24- for ( const file of eventFiles ) {
25- const filePath = path . join ( eventsPath , file ) ;
26- logger . debug ( `Loading event: ${ filePath } ` , { file : filePath } ) ;
27- const event = require ( filePath ) ;
28- if ( event . once ) {
29- client . once ( event . name , ( ...args ) => event . execute ( ...args ) ) ;
30- } else {
31- client . on ( event . name , ( ...args ) => event . execute ( ...args ) ) ;
25+ for ( const file of eventFiles ) {
26+ const filePath = path . join ( eventsPath , file ) ;
27+ logger . debug ( `Loading event: ${ filePath } ` , { file : filePath } ) ;
28+ const event = require ( filePath ) ;
29+ if ( event . once ) {
30+ client . once ( event . name , ( ...args ) => event . execute ( ...args ) ) ;
31+ } else {
32+ client . on ( event . name , ( ...args ) => event . execute ( ...args ) ) ;
33+ }
3234 }
35+ } catch ( err ) {
36+ logger . error ( `Failed to load events: ${ err . message } ` , err ) ;
3337 }
3438}
3539
3640function loadCommands ( ) {
37- const foldersPath = path . join ( __dirname , "commands" ) ;
38- const commandFolders = fs . readdirSync ( foldersPath ) ;
41+ try {
42+ const foldersPath = path . join ( __dirname , "commands" ) ;
43+ const commandFolders = fs . readdirSync ( foldersPath ) ;
3944
40- for ( const folder of commandFolders ) {
41- const commandsPath = path . join ( foldersPath , folder ) ;
42- const commandFiles = fs
43- . readdirSync ( commandsPath )
44- . filter ( ( file ) => file . endsWith ( ".js" ) ) ;
45- for ( const file of commandFiles ) {
46- const filePath = path . join ( commandsPath , file ) ;
47- const command = require ( filePath ) ;
48- logger . debug ( `Loading command: ${ filePath } ` , { file : filePath } ) ;
45+ for ( const folder of commandFolders ) {
46+ const commandsPath = path . join ( foldersPath , folder ) ;
47+ const commandFiles = fs
48+ . readdirSync ( commandsPath )
49+ . filter ( ( file ) => file . endsWith ( ".js" ) ) ;
50+ for ( const file of commandFiles ) {
51+ const filePath = path . join ( commandsPath , file ) ;
52+ const command = require ( filePath ) ;
53+ logger . debug ( `Loading command: ${ filePath } ` , { file : filePath } ) ;
4954
50- // Initialize the command if it has an initializer
51- if ( "init" in command ) {
52- logger . debug ( `Initializing ${ filePath } ` , { file : filePath } ) ;
53- command . init ( ) ;
54- }
55+ // Initialize the command if it has an initializer
56+ if ( "init" in command ) {
57+ logger . debug ( `Initializing ${ filePath } ` , { file : filePath } ) ;
58+ command . init ( ) ;
59+ }
5560
56- // Set a new item in the Collection with the key as the command name and the value as the exported module
57- if ( "data" in command && "execute" in command ) {
58- client . commands . set ( command . data . name , command ) ;
59- } else {
60- logger . warn (
61- `The command at ${ filePath } is missing a required "data" or "execute" property.` ,
62- { file : filePath }
63- ) ;
61+ // Set a new item in the Collection with the key as the command name and the value as the exported module
62+ if ( "data" in command && "execute" in command ) {
63+ client . commands . set ( command . data . name , command ) ;
64+ } else {
65+ logger . warn (
66+ `The command at ${ filePath } is missing a required "data" or "execute" property.` ,
67+ { file : filePath }
68+ ) ;
69+ }
6470 }
6571 }
72+ } catch ( err ) {
73+ logger . error ( `Failed to load commands: ${ err . message } ` , err ) ;
6674 }
6775}
6876
0 commit comments