diff --git a/pterodactyl/pterodactyl.py b/pterodactyl/pterodactyl.py index a20b4d1..4b53973 100644 --- a/pterodactyl/pterodactyl.py +++ b/pterodactyl/pterodactyl.py @@ -1,3 +1,4 @@ +import asyncio import json import logging import re @@ -160,7 +161,17 @@ class Pterodactyl(commands.Cog): return tellraw def get_task(self): - return self.bot.loop.create_task(self.establish_websocket_connection(), name="Pterodactyl Websocket Connection") + task = self.bot.loop.create_task(self.establish_websocket_connection(), name="Pterodactyl Websocket Connection") + task.add_done_callback(self.error_callback) + return task + + def error_callback(self, fut): #NOTE - Thanks flame442 and zephyrkul for helping me figure this out + try: + fut.result() + except asyncio.CancelledError: + pass + except Exception as e: + self.logger.error("WebSocket task has failed: %s", e, exc_info=e) async def cog_load(self): self.task = self.get_task()