banner
二叉树树

二叉树树的xLog

Protect What You Love!
telegram
x
github
bilibili
steam_profiles
email

Build your QQBot using NoneBot2!

This article is a reset version of: https://xfeed.app/notes/71448-13


Install Lagrange.OneBot#

Used for logging into QQ to send and receive messages

  1. Go to Lagrange's Github Release and download the file according to your system.

  2. Unzip and run the only file.

  3. It will tell you that there is no configuration file; just ignore it and keep pressing Enter (you can modify it if you know how).

{
    "Logging": {
        "LogLevel": {
            "Default": "Information",
            "Microsoft": "Warning",
            "Microsoft.Hosting.Lifetime": "Information"
        }
    },
    "SignServerUrl": "https://sign.lagrangecore.org/api/sign/25765",
    "MusicSignServerUrl": "",
    "Account": {
        "Uin": 0,
        "Password": "",
        "Protocol": "Linux",
        "AutoReconnect": true,
        "GetOptimumServer": true
    },
    "Message": {
        "IgnoreSelf": true,
        "StringPost": false
    },
    "QrCode": {
        "ConsoleCompatibilityMode": false
    },
    "Implementations": [
        {
            "Type": "ReverseWebSocket",
            "Host": "127.0.0.1",   // Address, ensure it matches NoneBot2 later
            "Port": 8080,   // Port, ensure it matches NoneBot2 later
            "Suffix": "/onebot/v11/ws",   // Path, no need to change
            "ReconnectInterval": 5000,
            "HeartBeatInterval": 5000,
            "AccessToken": ""
        }
    ]
}
  1. Wait for it to pop up a QR code, scan it.

  2. Just leave it alone, let it be.

Install NoneBot2#

Used to implement logic and control Lagrange to send and receive messages

  1. First, you need to install Python.

  2. Tsinghua PyPI source: pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

  3. Install pipx: pip install pipx

  4. Set pipx global variable: pipx ensurepath

  5. Install nb-cli: pipx install nb-cli

  6. If the nb command cannot be found: For root users, you can edit /root/.bashrc or /root/.profile (if you are using Bash): nano /root/.bashrc and add the following line: export PATH="$HOME/.local/bin:$PATH" Save and reload the configuration: source /root/.bashrc

  7. Install nb bootstrap: nb self install nb-cli-plugin-bootstrap

  8. Create a new project, choose a folder you like, then: nb bs (just keep pressing Enter if you don't understand).

Example:

C:\afbot>nb bs
Loading adapter list...
Please enter the project name
[?] Please enter > onanibot
[?] Please select the adapter you want to use OneBot V11 (OneBot V11 protocol)
Please enter the Bot superuser, the superuser has the highest authority over the Bot (just fill in the QQ number for QQ integration) (leave blank and press Enter to finish input)
[?] Item 1 >
Please enter the Bot nickname, messages starting with the Bot nickname can replace @ (leave blank and press Enter to finish input)
[?] Item 1 >
Please enter the Bot command starting character, messages starting with the starting character will be recognized as commands,
If there is a command called query, it will only be triggered when this configuration item contains "/", use "/query" to trigger,
Leave blank to use the default ['', '/', '#'] (leave blank and press Enter to finish input)
[?] Item 1 >
Please enter the Bot command separator, generally used for secondary commands,
Leave blank to use the default ['.', ' '] (leave blank and press Enter to finish input)
[?] Item 1 >
Please enter the NoneBot2 listening address, if you want to open it to the public, change it to 0.0.0.0
[?] Please enter > 127.0.0.1
Please enter the NoneBot2 listening port, range 1 ~ 65535, please ensure that this port number is the same as the connection endpoint configuration or related to port mapping configuration
[?] Please enter > 8080
[?] Do you want to release a shortcut startup script in the project directory? Yes
[?] Do you want to redirect the storage path of the localstore plugin to the project path for easier migration of the Bot later? Yes
[?] Do you want to use the superuser Ping command reply plugin? Yes
[?] Do you want to install the logpile plugin to provide logging to file functionality? Yes
[?] Do you want to use the webui plugin to start the project in the startup script to manage NoneBot via the web? (This plugin is still in development and not recommended for production environments) No
Successfully created project onanibot
[?] Do you want to create a virtual environment? Yes
Creating virtual environment in C:\afbot\onanibot\.venv
Virtual environment created successfully
[?] Do you need to modify or clear pip's PyPI mirror source configuration? No
[?] Do you want to immediately install project dependencies? Yes
Installing project dependencies
Dependencies installed successfully
[?] Please select the built-in plugins to enable
Project configuration completed, let's get started!
  1. After the project is created, start it: nb run

  2. When you see: [INFO] nonebot | OneBot V11 | Bot XXXXXXXXXX connected, you have successfully connected to Lagrange.

  3. Test by sending a /ping to see if you get a Pong~.

  4. If you want to debug NoneBot2, please first use nb to enter the virtual environment. Then use pip install <package name>.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.