Backend Development 9 min read

Step-by-Step Guide to Setting Up a Mirai QQ Bot with Python

This tutorial walks you through the complete process of configuring the Mirai ecosystem, installing mirai-console-loader, handling login verification with Selenium, setting up mirai-api-http, configuring OpenJDK, and finally writing and running a Python bot using graia-application-mirai, providing detailed screenshots and code snippets.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
Step-by-Step Guide to Setting Up a Mirai QQ Bot with Python

The article introduces the Mirai ecosystem, explaining that the core consists of the Mirai framework, mirai-core, and mirai-core-api, and that developers can use the mirai-console plugin system to build QQ bots without directly handling low‑level protocols.

It then describes how to start Mirai by downloading and running mirai-console-loader (mcl) , showing screenshots of the download, extraction, and successful launch of the console.

When the console fails due to missing ChromeDriver for the mirai-login-solver-selenium plugin, the guide explains how to identify the required driver version, manually download it, rename it (e.g., chromedriver-86.0.4240.198.exe ), and replace the file in the appropriate directory.

Next, the tutorial addresses a signature verification error caused by using Oracle JDK, advising the replacement with OpenJDK, and provides steps to download, extract, and add the JDK path to system environment variables.

After configuring the environment, the guide shows how to install mirai-api-http by placing its JAR into the plugins folder and editing setting.yml (shown in a code block) to set authKey , host , port , and enable WebSocket.

<code># file: mcl-1.0.3/config/net.mamoe.mirai.api.http/setting.yml
authKey: graia-mirai-api-http-authkey
cacheSize: 4096
enableWebsocket: true
host: '0.0.0.0'
port: 8080</code>

With the backend ready, the article moves to Python development using graia-application-mirai . It instructs to install the library via pip install graia-application-mirai and provides a complete bot.py example that connects to the Mirai HTTP API, listens for friend messages, and replies with "Hello, World!".

<code>from graia.broadcast import Broadcast
from graia.application import GraiaMiraiApplication, Session
from graia.application.message.chain import MessageChain
import asyncio
from graia.application.message.elements.internal import Plain
from graia.application.friend import Friend

loop = asyncio.get_event_loop()

bcc = Broadcast(loop=loop)
app = GraiaMiraiApplication(
    broadcast=bcc,
    connect_info=Session(
        host="http://localhost:8080",
        authKey="graia-mirai-api-http-authkey",
        account=5234120587,
        websocket=True
    )
)

@bcc.receiver("FriendMessage")
async def friend_message_listener(app: GraiaMiraiApplication, friend: Friend):
    await app.sendFriendMessage(friend, MessageChain.create([
        Plain("Hello, World!")
    ]))

app.launch_blocking()
</code>

Finally, it advises testing the bot by sending any message from the QQ account; a successful reply confirms the setup. The guide concludes by encouraging readers to explore the official Mirai documentation for more advanced features.

backendPythonAutomationtutorialmiraiQQ bot
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.