HKUDS/nanobot · error · RuntimeError

napcat: not connected

Error message

napcat: not connected

What it means

Sentinel guard in _call_action: the NapCat/OneBot WebSocket is None (never started or already stopped), so the QQ action request cannot be sent. Fires when send() or member lookup is attempted before the websocket connection is established.

Solutions

  1. Ensure the channel's start() has completed and the NapCat WebSocket is connected before sending
  2. Check NapCat server availability and the configured WebSocket endpoint
  3. Retry after the connection reconnect loop re-establishes the socket
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at nanobot/channels/napcat/runtime.py:441 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of HKUDS/nanobot@42f37dc4c0 (2026-08-26). Data as JSON: /api/errors/07a334030b6690fe. Report an issue: GitHub.

Appendix: source

Thrown at nanobot/channels/napcat/runtime.py:441

        try:
            resp = await self._call_action(
                "get_group_member_info",
                {"group_id": group_id, "user_id": user_id, "no_cache": True},
            )
            data = resp.get("data", {})
            # logger.debug("get_group_member_info: {}", resp)
            return data.get("card") or data.get("nickname") or str(user_id)
        except Exception as e:
            logger.warning("napcat: get_group_member_info failed: {}", e)
            return str(user_id)

    # ------------------------------------------------------------------
    # Outbound
    # ------------------------------------------------------------------

    async def send(self, msg: OutboundMessage) -> None:
        if self._ws is None:
            raise RuntimeError("napcat: not connected")

        kind, _, target = msg.chat_id.partition(":")
        if kind not in ("private", "group") or not target:
            logger.error("napcat: invalid chat_id '{}'", msg.chat_id)
            return

        segments: list[dict[str, Any]] = []
        for ref in msg.media or []:
            if seg := await self._build_image_segment(ref):
                segments.append(seg)
        if text := (msg.content or "").strip():
            segments.append({"type": "text", "data": {"text": text}})
        if not segments:
            return

        params: dict[str, Any] = {"message": segments}
        if kind == "group":
            params["message_type"] = "group"

View on GitHub (pinned to 42f37dc4c0)