HKUDS/nanobot · error · RuntimeError

QQ client not initialized

Error message

QQ client not initialized

What it means

Sentinel guard in QQ channel send(): self._client is None because the channel was never started or was already stopped, so no QQ/official-client session exists to deliver the outbound message. The faulty input is the channel lifecycle state, not the message.

Solutions

  1. Ensure channel start() completes and establishes the QQ client before messages are sent
  2. Check QQ channel credentials/config so startup doesn't fail silently
  3. Restart the bot if the channel was stopped while the agent loop still routes messages to it
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at nanobot/channels/qq/runtime.py:303 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/a20ed21557bbf392. Report an issue: GitHub.

Appendix: source

Thrown at nanobot/channels/qq/runtime.py:303

                await self._client.close()
        self._client = None

        if self._http:
            with suppress(Exception):
                await self._http.close()
        self._http = None

        self.logger.info("bot stopped")

    # ---------------------------
    # Outbound (send)
    # ---------------------------

    async def send(self, msg: OutboundMessage) -> None:
        """Send attachments first, then text."""
        try:
            if not self._client:
                raise RuntimeError("QQ client not initialized")

            msg_id = msg.metadata.get("message_id")
            chat_type = self._chat_type_cache.get(msg.chat_id, "c2c")
            is_group = chat_type == "group"

            # 1) Send media
            for media_ref in msg.media or []:
                ok = await self._send_media(
                    chat_id=msg.chat_id,
                    media_ref=media_ref,
                    msg_id=msg_id,
                    is_group=is_group,
                )
                if not ok:
                    filename = (
                        os.path.basename(urlparse(media_ref).path)
                        or os.path.basename(media_ref)
                        or "file"

View on GitHub (pinned to 42f37dc4c0)