@@ -153,7 +153,9 @@ export class Fire extends AkairoClient {
153153 config : typeof config . fire ;
154154 useCanary : boolean ;
155155 declare util : Util ;
156+
156157 db : PGClient ;
158+ dbPromise : ReturnType < typeof connect > ;
157159
158160 constructor ( manager : Manager , sentry ?: typeof Sentry ) {
159161 super ( { ...config . akairo , ...config . discord } ) ;
@@ -442,13 +444,14 @@ export class Fire extends AkairoClient {
442444 if ( reconnect ) await this . util . sleep ( 2500 ) ; // delay reconnect
443445 this . getLogger ( "DB" ) . warn ( "Attempting to connect..." ) ;
444446 try {
445- this . db = await connect ( {
447+ this . dbPromise = connect ( {
446448 host : process . env . POSTGRES_HOST ,
447449 user : process . env . POSTGRES_USER ,
448450 password : process . env . POSTGRES_PASS ,
449451 database : process . env . POSTGRES_DB ,
450452 ssl : SSLMode . Disable , // we're connecting locally
451453 } ) ;
454+ this . db = await this . dbPromise ;
452455 } catch ( err ) {
453456 this . getLogger ( "DB" ) . error ( "Failed to connect\n" , err . stack ) ;
454457 return this . manager . kill ( "db_error" ) ;
@@ -470,6 +473,7 @@ export class Fire extends AkairoClient {
470473
471474 async login ( ) {
472475 if ( ! this . options . shards ) this . options . shards = [ this . manager . id || 0 ] ;
476+ await this . dbPromise ; // ensure we're connected before logging in
473477 this . getLogger ( "Discord" ) . warn (
474478 `Attempting to login on cluster ${ this . manager . id } with shards [${ (
475479 this . options . shards as number [ ]
0 commit comments