@@ -82,7 +82,9 @@ export default class DiscordModuleLoader {
8282 if ( ! existsSync ( resolve ( dir , folder , "index.js" ) ) )
8383 throw new Error ( `Couldn't find index.js in ${ folder } ` ) ;
8484
85- const guild = ( await import ( resolve ( dir , folder , "index.js" ) ) ) . default ;
85+ let guild = ( await import ( resolve ( dir , folder , "index.js" ) ) ) . default ;
86+
87+ if ( typeof guild === "function" ) guild = await guild ( ) ;
8688
8789 if ( ! ( guild instanceof DiscordGuild ) )
8890 throw new Error ( `Guild ${ folder } is not an Guild.` ) ;
@@ -141,7 +143,9 @@ export default class DiscordModuleLoader {
141143 if ( ! existsSync ( resolve ( dir , folder , "index.js" ) ) )
142144 throw new Error ( `Couldn't find index.js in ${ folder } ` ) ;
143145
144- const module = ( await import ( resolve ( dir , folder , "index.js" ) ) ) . default ;
146+ let module = ( await import ( resolve ( dir , folder , "index.js" ) ) ) . default ;
147+
148+ if ( typeof module === "function" ) module = await module ( ) ;
145149
146150 if ( ! ( module instanceof DiscordModule ) )
147151 throw new Error ( `Module ${ folder } is not an Module` ) ;
@@ -194,7 +198,9 @@ export default class DiscordModuleLoader {
194198
195199 const returnEvents : [ string , DiscordEvent < any > ] [ ] = [ ] ;
196200 for ( const file of events ) {
197- const event = ( await import ( resolve ( dir , file ) ) ) . default ;
201+ let event = ( await import ( resolve ( dir , file ) ) ) . default ;
202+
203+ if ( typeof event === "function" ) event = await event ( ) ;
198204
199205 if ( ! ( event instanceof DiscordEvent ) )
200206 throw new Error ( `Event ${ file } is not an Event` ) ;
@@ -244,7 +250,9 @@ export default class DiscordModuleLoader {
244250
245251 const returnCommands : [ string , DiscordCommand ] [ ] = [ ] ;
246252 for ( const file of commands ) {
247- const command = ( await import ( resolve ( dir , file ) ) ) . default ;
253+ let command = ( await import ( resolve ( dir , file ) ) ) . default ;
254+
255+ if ( typeof command === "function" ) command = await command ( ) ;
248256
249257 if ( ! ( command instanceof DiscordCommand ) )
250258 throw new Error ( `Command ${ file } is not a Command` ) ;
0 commit comments