NekoBot supports the QQ platform through the OneBot V11 protocol.
OneBot V11 is the successor to CQHTTP, a universal robot message interface standard.
NapCatQQ is a OneBot V11 implementation based on NTQQ.
git clone https://github.com/NapNeko/NapCatQQ.git
cd NapCatQQ
docker run -d --name napcat -p 6299:6299 ghcr.io/mlikiowa/napcat-docker:latestEdit data/platforms_sources.json:
{
"aiocqhttp": {
"type": "aiocqhttp",
"enable": true,
"id": "aiocqhttp",
"name": "NekoBot",
"ws_host": "0.0.0.0",
"ws_port": 6299,
"command_prefix": "/"
}
}Set up WebSocket service in NapCatQQ configuration file:
onebot:
http:
enable: false
ws:
enable: true
host: 0.0.0.0
port: 6299python main.pyNekoBot supports the following QQ events:
| Event Type | Description |
|---|---|
| Group Message | Messages in groups |
| Private Message | Private messages |
| Group Notice Message | Group notice messages (e.g., join, leave) |
| Channel Message | QQ channel messages |
| Event Type | Description |
|---|---|
| Group Member Increase | New member joins group |
| Group Member Decrease | Member leaves group |
| Group Mute | Group mute event |
| Friend Add | Friend add event |
await self.send_group_message(
group_id=123456,
user_id=789,
message="Hello!",
platform_id="aiocqhttp"
)await self.send_private_message(
user_id=789,
message="Hello!",
platform_id="aiocqhttp"
)import httpx
async def send_image(self, group_id, user_id, image_url):
await self.send_group_message(
group_id=group_id,
user_id=user_id,
message=f"[CQ:image,file={image_url}]",
platform_id="aiocqhttp"
)async def send_rich_message(self, group_id, user_id):
message = (
"Welcome to NekoBot!\n"
"[CQ:face,id=128]\n"
"Click for more: https://example.com"
)
await self.send_group_message(
group_id=group_id,
user_id=user_id,
message=message,
platform_id="aiocqhttp"
)OneBot V11 uses CQ codes to represent special message elements:
| CQ Code | Description | Example |
|---|---|---|
[CQ:image,file=xxx] | Image | [CQ:image,file=http://example.com/image.jpg] |
[CQ:record,file=xxx] | Voice | [CQ:record,file=http://example.com/audio.mp3] |
[CQ:at,id=xxx] | Mention | [CQ:at,id=123456] |
[CQ:face,id=xxx] | Emoji | [CQ:face,id=128] |
[CQ:share,url=xxx] | Link share | [CQ:share,url=https://example.com] |
[CQ:music,id=xxx] | Music share | [CQ:music,id=123456] |
async def kick_user(self, group_id, user_id, reject_add_request=False):
await self.platform_server.call_platform_api(
platform_id="aiocqhttp",
action="set_group_kick",
params={"group_id": group_id, "user_id": user_id, "reject_add_request": reject_add_request}
)
async def mute_user(self, group_id, user_id, duration=60):
await self.platform_server.call_platform_api(
platform_id="aiocqhttp",
action="set_group_ban",
params={"group_id": group_id, "user_id": user_id, "duration": duration}
)async def add_friend(self, user_id, comment=""):
await self.platform_server.call_platform_api(
platform_id="aiocqhttp",
action="set_friend_add_request",
params={"flag": flag, "approve": True, "remark": comment}
)async def get_group_members(self, group_id):
result = await self.platform_server.call_platform_api(
platform_id="aiocqhttp",
action="get_group_member_list",
params={"group_id": group_id}
)
return result.get("data", [])Check the following:
Ensure the bot account has the following permissions: