HKUDS/nanobot · error · RuntimeError

Discord client is not ready

Error message

Discord client is not ready

What it means

Raised by Discord send when the discord.py client is not logged in/ready (self._user missing) — the send was invoked before startup completed or after a disconnect/stop. The message cannot be routed to a guild channel or DM.

Solutions

  1. Ensure start() has completed and the client is connected before sending
  2. Restart the channel if the client dropped its session
  3. Queue outbound messages until the ready event fires
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at nanobot/channels/discord/runtime.py:471 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/9a39916c112b5ec5. Report an issue: GitHub.

Appendix: source

Thrown at nanobot/channels/discord/runtime.py:471

            await self._client.start(self.config.token)
        except asyncio.CancelledError:
            raise
        except Exception:
            self.logger.exception("client startup failed")
        finally:
            self._running = False
            await self._reset_runtime_state(close_client=True)

    async def stop(self) -> None:
        """Stop the Discord channel."""
        self._running = False
        await self._reset_runtime_state(close_client=True)

    async def send(self, msg: OutboundMessage) -> None:
        """Send a message through Discord using discord.py."""
        client = self._client
        if client is None or not client.is_ready():
            raise RuntimeError("Discord client is not ready")

        is_progress = isinstance(msg.event, ProgressEvent)

        try:
            await client.send_outbound(msg)
        except Exception:
            self.logger.exception("Error sending message")
            raise
        finally:
            if not is_progress:
                await self._stop_typing(msg.chat_id)
                await self._clear_reactions(msg.chat_id)

    async def send_delta(
        self,
        chat_id: str,
        delta: str,
        metadata: dict[str, Any] | None = None,

View on GitHub (pinned to 42f37dc4c0)