← Writing

Common NapCat Errors

9 min read#NapCat#OneBot#QQ#Autarkia

Almost a year of running an agent on QQ through NapCat, written down by category. Most of these are not NapCat bugs — they are my own code or QQ itself — but the error always shows up in the NapCat log.

Table of Contents

Autarkia talks to QQ like this: NapCat runs a forward WebSocket server, my adapter connects to it, receives OneBot 11 events and sends actions. It has been running since the end of 2025, and the issue log has collected a fair number of entries about it. These are the ones other people are likely to hit too.

Two caveats first. Most of what follows is not a NapCat bug: either my code handed it something broken, or QQ simply works that way, and the error merely surfaces in the NapCat log so it looks like NapCat at first glance. And every item describes the version I was running at the time; I have not gone back to check whether newer releases changed anything.

01CQ codes share one string with your text

When message is sent as a string, images and voice are written as [CQ:image,file=...] inline with the text. That means every text-processing function on the outbound path gets a chance to break them. I have seen three ways.

The first is long-message chunking. A user sent a two-word message and got back 60 messages of base64 garbage. That reply included voice, sent as [CQ:record,file=base64://...], tens of thousands of characters in a single code. An outbound helper split long text every 1200 characters and knew nothing about CQ codes, so it cut straight through. None of the fragments parsed as a voice message, and NapCat sent each one as plain text.

The second is text cleanup. Sending a meme made NapCat report ENOENT: no such file or directory, and on a close look the path in the log had turned a directory named like my_meme_pack into mymemepack. QQ does not render markdown, so the outbound path strips *italic* and _italic_ markers, with a regex like this:

python
re.sub(r"_(.+?)_", r"\1", text)   # 路径里成对的下划线也会被当成斜体

I misdiagnosed this one the first time. Seeing ENOENT, I decided that NapCat was a separate process and could not read my files, switched every image to base64, and the problem went away, so I called it fixed. It only went away because base64 contains no underscores. With NapCat and the adapter on the same machine, file:/// plus an absolute path works fine, and I later switched back.

That wrong diagnosis does become true in a container, though. Under napcat-docker, NapCat sees the container filesystem and a host path does not exist there unless the image directory is mounted in. I am inferring this from the compose file; I have not actually run into it yet.

The third is home-made tags. I let the model write [MEME:category] to mean "send a meme here", and the adapter swaps the tag for an image. Sometimes the model invents a category that does not exist; no image gets picked and the tag stays in the text. [name:args] has the same shape as a CQ code, and what the user saw was a truncated [MEM. I never traced which layer did the truncating. The takeaway is just that a custom tag must be either replaced or removed before the message leaves.

All three fixes make text processing step around CQ codes: swap them for placeholders before chunking and swap them back afterwards, and skip markdown cleanup when the message contains [CQ:. It works, but it is patching holes one at a time. If I were starting over I would send message as a segment array, which OneBot 11 supports natively:

python
"message": [
    {"type": "text", "data": {"text": "早"}},
    {"type": "image", "data": {"file": "file:///home/me/memes/a.png"}},
]

Text and media are separate from the start, cleanup only touches text segments, and there is no way for text to be mistaken for a CQ code. Autarkia still uses strings; I have not migrated.

02An action without echo has no receipt

One reply: a voice clip, then text. In the adapter log the voice goes first. In QQ the text arrives first.

My first version of sending was: serialise send_private_msg, await ws.send(...), and treat the return as "sent". That await only waits for the bytes to be written to the connection. Voice still has to be transcoded and uploaded on the NapCat side; text does not, so text submitted a few milliseconds later overtakes it.

To know a message has really gone out, put an echo in the request and wait for the response carrying the same echo:

python
echo = f"call_{seq}"
pending[echo] = fut = loop.create_future()
await ws.send(json.dumps({"action": "send_private_msg", "params": params, "echo": echo}))
resp = await asyncio.wait_for(fut, timeout=30)   # 接收循环里按 echo 找到 fut 并 set_result
ok = resp.get("status") == "ok" and resp.get("retcode") == 0

A few things are easy to get wrong here. The receive loop must not be blocked by message handling, or nobody reads the response and every call runs to its timeout, so events go to a new task. On disconnect, every pending future has to be failed. And a timeout is not a failure: NapCat may just be slow at transcoding and deliver the voice a moment later. On timeout I currently fall back to sending that segment as text, which in theory can leave the user with both the voice and the text. I have not dealt with that yet.

Also, a successful response says nothing about the other side. I have a feature where two accounts message each other privately. Once one of them was not logged in at all, and the other kept sending and kept getting success, because QQ stores messages for offline users. Whether the peer is online needs separate evidence; the send result is not it.

03Transparent PNGs get a white box, and the mface detour

Most memes are PNGs with a transparent background. Sent with [CQ:image], the other side sees them on white: QQ's image upload converts them to JPG, which has no alpha channel. Adding subType=1 to send them as stickers additionally pads odd-sized images with a white border.

Stickers you have saved inside QQ do keep their transparency, so I tried that route: add_custom_face to save the image, then send it as an mface segment. I spent a week on it and then deleted the code. Here is what I ran into, to save someone else the trip.

  • fetch_custom_face_detail returns fields named md5, epId and resId, while mface wants emoji_id, emoji_package_id and key. I read the response using the second set of names, always got empty values, and the code silently fell back to CQ:image, which looked like "mface has no effect". The mapping is md5 → emoji_id, epId → emoji_package_id, resId → key, desc → summary.
  • Give count enough room. With many saved stickers, the default handful will not include the one just added. I use 200.
  • Strip commas, square brackets and & from summary before putting it in a CQ code, or you are back to the previous section.
  • With several accounts, cache the resolved fields per account. An id from account A's collection will not send from account B.
  • With the fields right, a freshly added sticker sends, and some time later you get EventChecker Failed: sendMsg result=-13100. In QQ's data directory, Ori and Thumb under personal_emoji were empty: adding a sticker wrote the record but never placed the image files, and it only sent at first because of an in-memory cache.
  • The collection is capped at 500. With over a thousand memes in the library, each one has to be removed with delete_custom_face after sending.

For -13100 I tried placing the files into Ori and Thumb myself, and it sent. But that means hand-writing files into QQ's data directory, plus add-send-delete for every image, and I did not want to maintain it. mface was meant for store stickers, and saved stickers only happen to have fields that line up. This part is QQ's own implementation; there is nothing for NapCat to fix.

What I do now is a step back: memes go out as CQ:image and I live with the white background, and mface is only used for the few stickers already saved by hand in the account, matched by desc and skipped when not found.

04Installed, but it will not connect

  • The WebUI shows a single line, {"code":-1}. I was running from source and had not built the frontend.
  • After adding a second account the adapter could not reach its port. OneBot 11 config is one file per account (onebot11_<uin>.json), and the new account's file had no WebSocket server; it has to be added again. After an account is removed, these files stay behind in config/.
  • On a failed handshake, compare tokens first. My adapter sent both an Authorization: Bearer header and an access_token URL parameter, and I later noticed the connection log printed the whole URL, token included. The header alone is enough.
  • If login fails or no messages arrive, check the QQ version. At the end of 2025, QQ 9.9.21 and above did not work with the NapCat of the time, and downgrading to 9.9.17 fixed it. The numbers are certainly different now, but "QQ auto-updated and NapCat stopped working" keeps coming back.
  • Parameter names for the same action differ between versions. For get_forward_msg I now try id first and message_id on failure, and the result of fetch_custom_face_detail is sometimes under data.emojiInfoList and sometimes data is the list itself.
  • With napcat-docker: MODE=ws generates a forward WebSocket config; leaving ACCOUNT unset stops at the QR screen, and the code shows up right in docker logs; the login state lives in the mounted QQ directory, and deleting it means scanning again. Memory is about 185 MB per account idle and 250 to 400 MB once logged in.

For several accounts, run one NapCat instance and one port per account. Take the bot's own QQ number from self_id in the event instead of keeping it in config and comparing; you will forget it when the account changes.

05Whether to put an agent on QQ at all

After all these pitfalls, a word on the choice itself. NapCat is not an official interface; it works by attaching to the QQ client. Two risks follow that no amount of fixing removes: the account can be flagged, and any QQ update can break it.

The official bot platform has neither risk. I have integrated it too, and I do not recommend it. Its one advantage is that registering is easy. The drawbacks are many; to name two, a bot gets only a few proactive messages a month, and a reply cannot be split into several bubbles sent in a row.

So my advice is to build your own client, web or Android. Autarkia now has its own web and Android clients, and QQ is just one of the entrances. There are open-source clients you could plug into instead; I have not used them and will not name one.

Building the client is not the hard part: a chat screen and a WebSocket. The hard part is the network. The backend runs on a machine at home, and the phone has to reach it when you are out. That is the problem QQ was really solving for you. I have written that part up separately.

Reaching a self-hosted backend from outside