mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-20 07:54:36 +00:00
Add Client.setup_hook
This commit is contained in:
parent
1d1bba1f90
commit
68b7ee6b99
@ -488,7 +488,8 @@ class Client:
|
||||
async def login(self, token: str) -> None:
|
||||
"""|coro|
|
||||
|
||||
Logs in the client with the specified credentials.
|
||||
Logs in the client with the specified credentials and
|
||||
calls the :meth:`setup_hook`.
|
||||
|
||||
|
||||
Parameters
|
||||
@ -512,6 +513,8 @@ class Client:
|
||||
data = await self.http.static_login(token.strip())
|
||||
self._connection.user = ClientUser(state=self._connection, data=data)
|
||||
|
||||
await self.setup_hook()
|
||||
|
||||
async def connect(self, *, reconnect: bool = True) -> None:
|
||||
"""|coro|
|
||||
|
||||
@ -646,6 +649,22 @@ class Client:
|
||||
await self.login(token)
|
||||
await self.connect(reconnect=reconnect)
|
||||
|
||||
async def setup_hook(self) -> None:
|
||||
"""|coro|
|
||||
|
||||
A coroutine to be called to setup the bot, by default this is blank.
|
||||
|
||||
To perform asynchronous setup after the bot is logged in but before
|
||||
it has connected to the Websocket, overwrite this coroutine.
|
||||
|
||||
This is only called once, in :meth:`login`, and will be called before
|
||||
any events are dispatched, making it a better solution than doing such
|
||||
setup in the :func:`~discord.on_ready` event.
|
||||
|
||||
.. versionadded:: 2.0
|
||||
"""
|
||||
pass
|
||||
|
||||
def run(self, *args: Any, **kwargs: Any) -> None:
|
||||
"""A blocking call that abstracts away the event loop
|
||||
initialisation from you.
|
||||
|
Loading…
x
Reference in New Issue
Block a user