Add logout method (#114)
This commit is contained in:
parent
132521fa39
commit
e2061adc55
@ -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
|
``aiohttp.ClientSession``. You can specify a custom ``connector`` or any other
|
||||||
session parameter supported by ``aiohttp``.
|
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
|
### Default Allowed Mentions
|
||||||
|
|
||||||
Specify default mention behaviour for all outgoing messages when constructing the client:
|
Specify default mention behaviour for all outgoing messages when constructing the client:
|
||||||
|
@ -454,15 +454,23 @@ class Client:
|
|||||||
await self.close()
|
await self.close()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
async def close_gateway(self, code: int = 1000) -> None:
|
async def close_gateway(self, code: int = 1000) -> None:
|
||||||
"""Closes only the gateway connection, allowing for potential reconnect."""
|
"""Closes only the gateway connection, allowing for potential reconnect."""
|
||||||
if self._shard_manager:
|
if self._shard_manager:
|
||||||
await self._shard_manager.close()
|
await self._shard_manager.close()
|
||||||
self._shard_manager = None
|
self._shard_manager = None
|
||||||
if self._gateway:
|
if self._gateway:
|
||||||
await self._gateway.close(code=code)
|
await self._gateway.close(code=code)
|
||||||
self._gateway = None
|
self._gateway = None
|
||||||
self._ready_event.clear() # No longer ready if gateway is closed
|
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:
|
def is_closed(self) -> bool:
|
||||||
"""Indicates if the client has been closed."""
|
"""Indicates if the client has been closed."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user