diff --git a/pterodactyl/pterodactyl.py b/pterodactyl/pterodactyl.py index aa819a7..c279715 100644 --- a/pterodactyl/pterodactyl.py +++ b/pterodactyl/pterodactyl.py @@ -29,6 +29,7 @@ class Pterodactyl(commands.Cog): try: client = PterodactylClient(base_url, api_key).client websocket_credentials = client.servers.get_websocket(server_id) + self.logger.debug("Websocket connection details retrieved: " + websocket_credentials) except exceptions.ClientConfigError as e: self.logger.error(f'Failed to initialize Pterodactyl client: {e}') return @@ -49,9 +50,14 @@ class Pterodactyl(commands.Cog): while True: message = await websocket.recv() - if json.loads(message)['event'] == 'token expiring': + if json.loads(message)['event'] in ['token expiring', 'token expired']: + self.logger.debug("Received token expiring/expired event. Refreshing token.") websocket_credentials = client.servers.get_websocket(server_id) auth_message = json.dumps({"event": "auth", "args": [websocket_credentials['data']['token']]}) + await websocket.send(auth_message) + self.logger.debug("Authentication message sent") + if json.loads(message)['event'] == 'auth success': + self.logger.debug("Authentication successful") self.logger.debug("Received message: %s", message) async def cog_load(self):