This article is updated synchronously to xLog by Mix Space
For the best browsing experience, it is recommended to visit the original link
https://www.do1e.cn/posts/code/building-your-own-qq-bot
Introduction#
Recently, I found that the WebUI of NapCatQQ has been improved, making it quite suitable for beginners, so I wrote this article.
This article only covers the basic usage methods and may lack some advanced features. However, it is also necessary to understand the following basic knowledge: command line, HTTP protocol, Docker, Python, and it is not completely zero-based. (If you only want to use Webhook for notifications or use existing NoneBot plugins, Python programming is not required.)
The tools used are NapCatQQ and NoneBot. The former runs QQ and connects to protocols like OneBot11, while the latter is a framework implemented based on Python calling protocols. You can refer to the official documentation if you encounter problems. (If you only want to use Webhook for notifications, you can set up NapCatQQ.)
Preparation#
- A server, no restrictions on internal or external networks.
- A QQ number as a QQ bot; it is not recommended to use your main account.
QQ can detect whether plugins are being used, and your account may encounter the following issues: forced logout, login restrictions, freezing.
Please evaluate and decide whether to continue trying to use it based on your actual situation; the author is not responsible for any consequences of building a bot based on this article.
NapCatQQ#
Installation#
There are many installation methods for NapCatQQ, but since it is a service, I still recommend using Docker to install the Shell version: https://napneko.github.io/guide/boot/Shell#napcat-docker-linux-container-deployment
The Docker container comes with the NTQQ body, so there is no need to install the corresponding version of QQ separately.
At this point, you can access http://[IP]:6099/webui to see the NTQQ web page, where you can log in and set up. The login password can be found in the log file (default: napcat
), and it is recommended to change it after logging in.
You can also use docker logs napcat
to view the logs and scan the QR code to log in to QQ.
It is recommended to check the option for no mobile verification after scanning the QR code.
Enable HTTP Protocol#
In the WebUI, find Network Configuration -> New -> HTTP Server
, and name, Host, and port can be arbitrary. It is recommended to choose Array
for the message format; actual testing shows it is compatible with String
, and you can send mixed messages of text and images. It is strongly recommended to fill in the Token to prevent malicious requests.
Once enabled, you can test it in API Debugging -> HTTP
or any other API testing tool you are comfortable with. The API can be referenced at: https://napcat.apifox.cn/
There are two ways to use the Token:
- Add
Authorization: [Token]
in the request header.
- Add
?access_token=[Token]
in the URL.
Use Webhook for Notifications#
The most important interfaces here are sending private messages and sending group messages, which can be found in API Debugging -> HTTP
. There is also a message construction feature, which is quite simple.
Here is an example of sending a private message:
Some applications use shoutrrr as the implementation of Webhook; you can refer to the following configuration:
Some applications may already support the OneBot11 protocol; in this case, just fill in http://[IP]:3000
, the Token, and the target QQ number.
nginx Reverse Proxy#
If you have a domain name, you can refer to the following nginx configuration example for NapCatQQ:
NoneBot#
The documentation is already quite complete, so I won't elaborate on it here.