diff --git a/src/middleware/BaseClient.js b/src/middleware/BaseClient.js index f128a92..afde573 100644 --- a/src/middleware/BaseClient.js +++ b/src/middleware/BaseClient.js @@ -37,7 +37,23 @@ class BaseClient extends EventEmitter { async build() { - const start = Date.now(); + let start = Date.now(); + + // const API = this._options.api.load ? await import('/Documents/My programs/GBot/api/index.js') + // .catch(() => this.logger.warn(`Error importing API files, continuing without`)) : null; + let API = null; + if (this._options.api.load) API = await import('../../api/index.js').catch(() => this.logger.warn(`Error importing API files, continuing without`)); + if (API) { + this.logger.info('Booting up API'); + const { default: APIManager } = API; + this.api = new APIManager(this, this._options.api); + await this.api.init(); + const now = Date.now(); + this.logger.info(`API ready. Took ${now - start} ms`); + start = now; + } + + this.logger.status(`Starting bot shards`); await this.shardingManager.spawn().catch((error) => { this.logger.error(`Fatal error during shard spawning:\n${error.stack || error}`); // eslint-disable-next-line no-process-exit @@ -46,18 +62,6 @@ class BaseClient extends EventEmitter { this.logger.status(`Shards spawned, spawned ${this.shardingManager.shards.size} shards. Took ${Date.now() - start} ms`); - // const API = this._options.api.load ? await import('/Documents/My programs/GBot/api/index.js') - // .catch(() => this.logger.warn(`Error importing API files, continuing without`)) : null; - let API = null; - if(this._options.api.load) API = await import('../../api/index.js').catch(() => this.logger.warn(`Error importing API files, continuing without`)); - if (API) { - this.logger.info('Booting up API'); - const { default: APIManager } = API; - this.api = new APIManager(this, this._options.api); - await this.api.init(); - this.logger.info('API ready.'); - } - this._built = true; this.readyAt = Date.now();