Skip to content
18 changes: 14 additions & 4 deletions interactions/client/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Client:

def __init__(
self,
token: str,
token: Optional[str] = None,
cache_limits: Optional[Dict[type, int]] = None,
intents: Intents = Intents.DEFAULT,
shards: Optional[List[Tuple[int]]] = None,
Expand Down Expand Up @@ -189,11 +189,11 @@ def latency(self) -> float:

return self._websocket.latency * 1000

def start(self) -> None:
def start(self, token: Optional[str] = None) -> None:
"""Starts the client session."""

try:
self._loop.run_until_complete(self._ready())
self._loop.run_until_complete(self._ready(token=token))
except (CancelledError, Exception) as e:
self._loop.run_until_complete(self._logout())
raise e from e
Expand Down Expand Up @@ -396,7 +396,7 @@ def __check_options(command, data):

return clean, _command

async def _ready(self) -> None:
async def _ready(self, token: Optional[str] = None) -> None:
"""
Prepares the client with an internal "ready" check to ensure
that all conditions have been met in a chronological order:
Expand All @@ -415,6 +415,16 @@ async def _ready(self) -> None:
| |___ CALLBACK
LOOP
"""
if self._http and token and self._http is not token:
raise RuntimeError("You cannot pass a token to the bot twice!")
elif not (self._http or token):
raise RuntimeError("No token was passed to the bot!")

if token:
self._token = token
self._http = token
self._websocket._http = token # Update the websockets token if it wasn't set before

if isinstance(self._http, str):
self._http = HTTPClient(self._http, self._cache)

Expand Down