Skip to content

Commit

Permalink
feat: Add possibility to start bot via async context manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Snawe committed Nov 26, 2022
1 parent b20f134 commit 999c22f
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions discord/client.py
Expand Up @@ -251,6 +251,20 @@ def __init__(
VoiceClient.warn_nacl = False
_log.warning("PyNaCl is not installed, voice will NOT be supported")

async def __aenter__(self) -> Client:
loop = asyncio.get_running_loop()
self.loop = loop
self.http.loop = loop
self._connection.loop = loop

self._ready = asyncio.Event()

return self

async def __aexit__(self) -> None:
if not self.is_closed():
await self.close()

# internals

def _get_websocket(
Expand Down

0 comments on commit 999c22f

Please sign in to comment.