diff --git a/README.md b/README.md index b2c56ab..6709933 100644 --- a/README.md +++ b/README.md @@ -112,6 +112,10 @@ These options are forwarded to ``HTTPClient`` when it creates the underlying ``aiohttp.ClientSession``. You can specify a custom ``connector`` or any other session parameter supported by ``aiohttp``. +### Logging Out + +Call ``Client.logout`` to disconnect from the Gateway and clear the current bot token while keeping the HTTP session alive. Assign a new token and call ``connect`` or ``run`` to log back in. + ### Default Allowed Mentions Specify default mention behaviour for all outgoing messages when constructing the client: diff --git a/disagreement/client.py b/disagreement/client.py index b474477..fecc20e 100644 --- a/disagreement/client.py +++ b/disagreement/client.py @@ -454,15 +454,23 @@ class Client: await self.close() return False - async def close_gateway(self, code: int = 1000) -> None: - """Closes only the gateway connection, allowing for potential reconnect.""" - if self._shard_manager: - await self._shard_manager.close() - self._shard_manager = None - if self._gateway: - await self._gateway.close(code=code) - self._gateway = None - self._ready_event.clear() # No longer ready if gateway is closed + async def close_gateway(self, code: int = 1000) -> None: + """Closes only the gateway connection, allowing for potential reconnect.""" + if self._shard_manager: + await self._shard_manager.close() + self._shard_manager = None + if self._gateway: + await self._gateway.close(code=code) + self._gateway = None + self._ready_event.clear() # No longer ready if gateway is closed + + async def logout(self) -> None: + """Invalidate the bot token and disconnect from the Gateway.""" + await self.close_gateway() + self.token = "" + self._http.token = "" + self.user = None + self.start_time = None def is_closed(self) -> bool: """Indicates if the client has been closed."""