Step-by-Step Guide to Setting Up a Mirai QQ Bot with Python Using mirai-console-loader and mirai-api-http
This tutorial walks you through installing and configuring mirai-console-loader, solving captcha with mirai-login-solver-selenium, adding mirai-api-http for language extensibility, switching to OpenJDK, and finally writing a simple Python bot with graia-application-mirai that replies "Hello, World!" to friend messages.
This article provides a comprehensive tutorial for developing a QQ bot using the Mirai framework, focusing on Python developers while also covering the necessary Java/Kotlin components.
Mirai ecosystem : The core consists of mirai-core and mirai-core-api ; mirai-console wraps these for easier plugin development, and mirai-api-http exposes HTTP/WebSocket interfaces for other languages.
Starting with mirai-console-loader : Download the mirai-console-loader (mcl) from GitHub, unzip, open a command prompt, navigate to the folder, and run mcl . If configuration errors appear, edit the config file as shown in the screenshots.
Handling slide captcha with mirai-login-solver-selenium : After launching mcl , add the captcha‑solver plugin using the command mcl --update-package net.mamoe:mirai-login-solver-selenium --channel nightly --type plugin . Download the matching chromedriver manually, rename it (e.g., chromedriver-86.0.4240.198.exe ), and replace the file in the indicated directory before rerunning mcl and logging in.
Adding mirai-api-http for language extensibility : Place the downloaded mirai-api-http.jar into the plugins folder, then restart mcl . If a signature verification error occurs, replace Oracle JDK with OpenJDK and update the system environment variables accordingly.
Configuring OpenJDK : Download an OpenJDK build, extract it, place it in a convenient location, and add its bin directory to the system PATH variable.
mirai-api-http settings (setting.yml) :
authKey: graia-mirai-api-http-authkey
cacheSize: 4096
enableWebsocket: true
host: '0.0.0.0'
port: 8080Installing the Python library : Run pip install graia-application-mirai to install the Graia framework.
Python bot script (bot.py) :
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()Run the script; if the bot replies "Hello, World!" to a friend message, the setup is successful.
Conclusion : The steps above constitute a starter guide for building a Mirai‑based QQ bot. For more advanced features and API details, refer to the official Mirai documentation.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.