@@ -19,47 +19,57 @@ log("LOADING", "Loading Bot", LogCategory.INFO);
1919// Load Handlers
2020
2121const handlers = { } ;
22- const handlersPath = path . join ( __dirname , "src/handlers" ) ;
23- const handlerFiles = readdirSync ( handlersPath ) . filter ( ( file ) =>
24- file . endsWith ( ".js" )
25- ) ;
2622
27- for ( const file of handlerFiles ) {
28- const filePath = path . join ( handlersPath , file ) ;
29- const { default : command } = await import ( "file://" + filePath ) ;
23+ if ( readdirSync ( path . join ( __dirname , "src" ) ) . includes ( "handlers" ) ) {
24+ const handlersPath = path . join ( __dirname , "src/handlers" ) ;
25+ // Check if the handlers directory exists
3026
31- handlers [ file . split ( "." ) . shift ( ) ] = command ;
32- }
27+ const handlerFiles = readdirSync ( handlersPath ) . filter ( ( file ) =>
28+ file . endsWith ( ".js" )
29+ ) ;
30+
31+ for ( const file of handlerFiles ) {
32+ const filePath = path . join ( handlersPath , file ) ;
33+ const { default : command } = await import ( "file://" + filePath ) ;
34+
35+ handlers [ file . split ( "." ) . shift ( ) ] = command ;
36+ }
3337
34- log (
35- "LOADED" ,
36- `Loaded ${ handlerFiles . length } handler${ handlerFiles . length != 1 ? "s" : "" } ` ,
37- LogCategory . SUCCESS
38- ) ;
38+ log (
39+ "LOADED" ,
40+ `Loaded ${ handlerFiles . length } handler${
41+ handlerFiles . length != 1 ? "s" : ""
42+ } `,
43+ LogCategory . SUCCESS
44+ ) ;
45+ }
3946
4047// -----------------------------------------------------------------------------
4148// Load Schedules
4249
4350const schedules = [ ] ;
44- const schedulesPath = path . join ( __dirname , "src/schedules" ) ;
45- const scheduleFiles = readdirSync ( schedulesPath ) . filter ( ( file ) =>
46- file . endsWith ( ".js" )
47- ) ;
4851
49- for ( const file of scheduleFiles ) {
50- const filePath = path . join ( schedulesPath , file ) ;
51- const { default : command } = await import ( "file://" + filePath ) ;
52+ if ( readdirSync ( path . join ( __dirname , "src" ) ) . includes ( "schedules" ) ) {
53+ const schedulesPath = path . join ( __dirname , "src/schedules" ) ;
54+ const scheduleFiles = readdirSync ( schedulesPath ) . filter ( ( file ) =>
55+ file . endsWith ( ".js" )
56+ ) ;
5257
53- schedules . push ( command ) ;
54- }
58+ for ( const file of scheduleFiles ) {
59+ const filePath = path . join ( schedulesPath , file ) ;
60+ const { default : command } = await import ( "file://" + filePath ) ;
61+
62+ schedules . push ( command ) ;
63+ }
5564
56- log (
57- "LOADED" ,
58- `Loaded ${ scheduleFiles . length } schedule${
59- scheduleFiles . length != 1 ? "s" : ""
60- } `,
61- LogCategory . SUCCESS
62- ) ;
65+ log (
66+ "LOADED" ,
67+ `Loaded ${ scheduleFiles . length } schedule${
68+ scheduleFiles . length != 1 ? "s" : ""
69+ } `,
70+ LogCategory . SUCCESS
71+ ) ;
72+ }
6373
6474// -----------------------------------------------------------------------------
6575// Main Bot Code
0 commit comments