Skip to content

Instantly share code, notes, and snippets.

@owenconti
Created October 23, 2015 15:05
Show Gist options
  • Save owenconti/d7691938ff0611cf2bd6 to your computer and use it in GitHub Desktop.
Save owenconti/d7691938ff0611cf2bd6 to your computer and use it in GitHub Desktop.
// Load all files in the commands directory into an array
var commandDirs = ['./commands', './modules/customCommands'];
function loadFirstCommandDir() {
if ( commandDirs.length > 0 ) {
var dir = commandDirs[ 0 ];
loadCommandsFromDir( dirname );
} else {
// When we are out of dirs to load, start the bot
startBot();
}
}
function loadCommandsFromDir( dirname ) {
fs.readdir( dirname , function( err, files ) {
if ( err ) {
Log.log( 'ERROR: ' + err );
}
files.forEach( function(fileName) {
if ( fileName.indexOf( '.js' ) >= 0 ) {
commandFiles.push( require( dirname + '/' + fileName ) );
}
} );
// Remove the dirname from the commandDirs
commandDirs.shift();
loadFirstCommandDir();
});
}
loadFirstCommandDir();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment