async connect() {
        try {
            const data = await (this.options.maxShards === "auto" ? this.getBotGateway() : this.getGateway());
            if(!data.url || (this.options.maxShards === "auto" && !data.shards)) {
                throw new Error("Invalid response from gateway REST call");
            }
            if(data.url.includes("?")) {
                data.url = data.url.substring(0, data.url.indexOf("?"));
            }
            if(!data.url.endsWith("/")) {
                data.url += "/";
            }
            this.gatewayURL = data.url + "?v=" + Constants.GATEWAY_VERSION + "&encoding=" + (Erlpack ? "etf" : "json");

            if(this.options.compress) {
                this.gatewayURL += "&compress=zlib-stream";
            }

            if (this.options.maxShards === "auto") {
                if (!data.shards) {
                    throw new Error("Failed to autoshard due to lack of data from Discord.");
                }
                this.options.maxShards = data.shards;
                if(this.options.lastShardID === undefined) {
                    this.options.lastShardID = data.shards - 1;
                }
            }

            for(let i = this.options.firstShardID; i <= this.options.lastShardID; ++i) {
                this.shards.spawn(i);
            }
        } catch(err) {
            if(!this.options.autoreconnect) {
                throw err;
            }
            this.emit("error", err);
            await sleep(2000);
            return this.connect();
        }
    }
/**
    * Tells all shards to connect.
    * @returns {Promise} Resolves when all shards are initialized
    */
Tells all shards to connect.
@returns {Promise} Resolves when all shards are initialized
Tells all shards to connect . @returns { Promise } Resolves when all shards are initialized
async connect() {
        try {
            const data = await (this.options.maxShards === "auto" ? this.getBotGateway() : this.getGateway());
            if(!data.url || (this.options.maxShards === "auto" && !data.shards)) {
                throw new Error("Invalid response from gateway REST call");
            }
            if(data.url.includes("?")) {
                data.url = data.url.substring(0, data.url.indexOf("?"));
            }
            if(!data.url.endsWith("/")) {
                data.url += "/";
            }
            this.gatewayURL = data.url + "?v=" + Constants.GATEWAY_VERSION + "&encoding=" + (Erlpack ? "etf" : "json");
            if(this.options.compress) {
                this.gatewayURL += "&compress=zlib-stream";
            }
            if (this.options.maxShards === "auto") {
                if (!data.shards) {
                    throw new Error("Failed to autoshard due to lack of data from Discord.");
                }
                this.options.maxShards = data.shards;
                if(this.options.lastShardID === undefined) {
                    this.options.lastShardID = data.shards - 1;
                }
            }
            for(let i = this.options.firstShardID; i <= this.options.lastShardID; ++i) {
                this.shards.spawn(i);
            }
        } catch(err) {
            if(!this.options.autoreconnect) {
                throw err;
            }
            this.emit("error", err);
            await sleep(2000);
            return this.connect();
        }
    }
async connect ( ) { try { const data = await ( this . options . maxShards === "auto" ? this . getBotGateway ( ) : this . getGateway ( ) ) ; if ( ! data . url || ( this . options . maxShards === "auto" && ! data . shards ) ) { throw new Error ( "Invalid response from gateway REST call" ) ; } if ( data . url . includes ( "?" ) ) { data . url = data . url . substring ( 0 , data . url . indexOf ( "?" ) ) ; } if ( ! data . url . endsWith ( "/" ) ) { data . url += "/" ; } this . gatewayURL = data . url + "?v=" + Constants . GATEWAY_VERSION + "&encoding=" + ( Erlpack ? "etf" : "json" ) ; if ( this . options . compress ) { this . gatewayURL += "&compress=zlib-stream" ; } if ( this . options . maxShards === "auto" ) { if ( ! data . shards ) { throw new Error ( "Failed to autoshard due to lack of data from Discord." ) ; } this . options . maxShards = data . shards ; if ( this . options . lastShardID === undefined ) { this . options . lastShardID = data . shards - 1 ; } } for ( let i = this . options . firstShardID ; i <= this . options . lastShardID ; ++ i ) { this . shards . spawn ( i ) ; } } catch ( err ) { if ( ! this . options . autoreconnect ) { throw err ; } this . emit ( "error" , err ) ; await sleep ( 2000 ) ; return this . connect ( ) ; } }
Tells all shards to connect.
Tells all shards to connect .