diff --git a/botpy/client.py b/botpy/client.py index 3c37e04..69933d8 100644 --- a/botpy/client.py +++ b/botpy/client.py @@ -99,6 +99,8 @@ async def close(self) -> None: self._closed = True await self.http.close() + if hasattr(self, 'client'): + await self.client.close() def is_closed(self) -> bool: return self._closed @@ -242,6 +244,7 @@ async def bot_connect(self, session): _log.info("[botpy] 会话启动中...") client = BotWebSocket(session, self._connection) + self.client = client try: await client.ws_connect() except (Exception, KeyboardInterrupt, SystemExit) as e: diff --git a/botpy/gateway.py b/botpy/gateway.py index c7a9cae..0065efb 100644 --- a/botpy/gateway.py +++ b/botpy/gateway.py @@ -236,3 +236,7 @@ async def _send_heart(self, interval): await self.send_msg(json.dumps(payload)) await asyncio.sleep(interval) + + async def close(self): + await self._conn.close() + _log.info("[botpy] websocket连接关闭!")