async def connect(self, *, reconnect=True):
backoff = ExponentialBackoff()<EOL>while not self.is_closed():<EOL><INDENT>try:<EOL><INDENT>await self._connect()<EOL><DEDENT>except (OSError,<EOL>HTTPException,<EOL>GatewayNotFound,<EOL>ConnectionClosed,<EOL>aiohttp.ClientError,<EOL>asyncio.TimeoutError,<EOL>websockets.InvalidHandshake,<EOL>websockets.WebSocketProtocolError) as exc:<EOL><INDENT>self.dispatch('<STR_LIT>')<EOL>if not reconnect:<EOL><INDENT>await self.close()<EOL>if isinstance(exc, ConnectionClosed) and exc.code == <NUM_LIT:1000>:<EOL><INDENT>return<EOL><DEDENT>raise<EOL><DEDENT>if self.is_closed():<EOL><INDENT>return<EOL><DEDENT>if isinstance(exc, ConnectionClosed):<EOL><INDENT>if exc.code != <NUM_LIT:1000>:<EOL><INDENT>await self.close()<EOL>raise<EOL><DEDENT><DEDENT>retry = backoff.delay()<EOL>log.exception("<STR_LIT>", retry)<EOL>await asyncio.sleep(retry, loop=self.loop)<EOL><DEDENT><DEDENT>
|coro|

        Creates a websocket connection and lets the websocket listen
        to messages from discord. This is a loop that runs the entire
        event system and miscellaneous aspects of the library. Control
        is not resumed until the WebSocket connection is terminated.

        Parameters
        -----------
        reconnect: :class:`bool`
            If we should attempt reconnecting, either due to internet
            failure or a specific failure on Discord's part. Certain
            disconnects that lead to bad state will not be handled (such as
            invalid sharding payloads or bad tokens).

        Raises
        -------
        GatewayNotFound
            If the gateway to connect to discord is not found. Usually if this
            is thrown then there is a discord API outage.
        ConnectionClosed
            The websocket connection has been terminated.