diff --git a/pterodactyl/pterodactyl.py b/pterodactyl/pterodactyl.py index 50c4145..bd7b5c7 100644 --- a/pterodactyl/pterodactyl.py +++ b/pterodactyl/pterodactyl.py @@ -59,8 +59,7 @@ class Pterodactyl(commands.Cog): except exceptions.PterodactylApiError as e: return self.logger.error('Failed to retrieve Pterodactyl websocket: %s', e) - async for websocket in websockets.connect(websocket_credentials['data']['socket'], origin=base_url, ping_timeout=60): - try: + async with websockets.connect(websocket_credentials['data']['socket'], origin=base_url, ping_timeout=60) as websocket: self.logger.info("WebSocket connection established") auth_message = json.dumps({"event": "auth", "args": [websocket_credentials['data']['token']]}) @@ -107,10 +106,6 @@ class Pterodactyl(commands.Cog): console = self.bot.get_channel(await self.config.console_channel()) if console is not None: await console.send(f"Server status changed! `{json.loads(message)['args'][0]}`") - except (websockets.exceptions.ConnectionClosed) as e: - self.logger.info("WebSocket connection closed: %s", e) - websocket_credentials = client.servers.get_websocket(server_id) - continue def remove_ansi_escape_codes(self, text: str) -> str: ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')