@@ -71,7 +71,7 @@ class Client:
7171
7272 def __init__ (
7373 self ,
74- token : str ,
74+ token : Optional [ str ] = None ,
7575 cache_limits : Optional [Dict [type , int ]] = None ,
7676 intents : Intents = Intents .DEFAULT ,
7777 shards : Optional [List [Tuple [int ]]] = None ,
@@ -189,11 +189,15 @@ def latency(self) -> float:
189189
190190 return self ._websocket .latency * 1000
191191
192- def start (self ) -> None :
193- """Starts the client session."""
192+ def start (self , token : Optional [str ] = None ) -> None :
193+ """
194+ Starts the client session.
195+
196+ :param Optional[str] token: The token of bot.
197+ """
194198
195199 try :
196- self ._loop .run_until_complete (self ._ready ())
200+ self ._loop .run_until_complete (self ._ready (token = token ))
197201 except (CancelledError , Exception ) as e :
198202 self ._loop .run_until_complete (self ._logout ())
199203 raise e from e
@@ -396,7 +400,7 @@ def __check_options(command, data):
396400
397401 return clean , _command
398402
399- async def _ready (self ) -> None :
403+ async def _ready (self , token : Optional [ str ] = None ) -> None :
400404 """
401405 Prepares the client with an internal "ready" check to ensure
402406 that all conditions have been met in a chronological order:
@@ -414,7 +418,19 @@ async def _ready(self) -> None:
414418 | |___ SYNCHRONIZE
415419 | |___ CALLBACK
416420 LOOP
421+
422+ :param Optional[str] token: The token of bot.
417423 """
424+ if self ._http and token and self ._http is not token :
425+ raise RuntimeError ("You cannot pass a token to the bot twice!" )
426+ elif not (self ._http or token ):
427+ raise RuntimeError ("No token was passed to the bot!" )
428+
429+ if token :
430+ self ._token = token
431+ self ._http = token
432+ self ._websocket ._http = token # Update the websockets token if it wasn't set before
433+
418434 if isinstance (self ._http , str ):
419435 self ._http = HTTPClient (self ._http , self ._cache )
420436
0 commit comments