banner
AcoFork

AcoFork

LOVETOLOVE

Install NoneBot2+Lagrange

Installing Lagrange.OneBot#

Used to log in to QQ and send/receive messages

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

  2. Extract and run the only file.

  3. It will tell you that there is no configuration file, just ignore it and press Enter all the way (you can change it if you know how).

appsettings.json

{
    "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",   // Make sure it matches the address in the following NoneBot2 section
            "Port": 8080,   // Make sure it matches the port in the following NoneBot2 section
            "Suffix": "/onebot/v11/ws",   // Default, no need to change
            "ReconnectInterval": 5000,
            "HeartBeatInterval": 5000,
            "AccessToken": ""
        }
    ]
}
  1. Wait for the QR code to appear and scan it.

  2. Just leave it there, don't do anything.

Installing NoneBot2#

Used to implement logic and control the sending/receiving of messages in Lagrange

  1. First, you need to install Python.

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

  3. Install pipx: pip install pipx.

  4. Set the pipx global variable: pipx ensurepath.

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

  6. If you can't find the nb command: 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, and then run: nb bs (just press Enter if you don't understand).

Example:

C:\afbot>nb bs
Loading adapter list...
Please enter the project name
[?] 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 (fill in the QQ number for QQ docking) (leave blank and press Enter to finish input)
[?] Item 1 >
Please enter the Bot nickname, messages starting with the Bot nickname can be used instead of @ (leave blank and press Enter to finish input)
[?] Item 1 >
Please enter the Bot command prefix, messages starting with the prefix will be recognized as commands,
if there is a command called "query", when there is "/" in this configuration item, use "/query" to trigger,
leave blank to use the default value ['', '/', '#'] (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 value ['.', ' '] (leave blank and press Enter to finish input)
[?] Item 1 >
Please enter the NoneBot2 listening address, change it to 0.0.0.0 if you want to open it to the public
[?] Enter > 127.0.0.1
Please enter the NoneBot2 listening port, range 1 ~ 65535, please make sure that this port number is the same as the connection end configuration or related to the port mapping configuration
[?] 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 subsequent migration of the Bot? 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 start the project with the webui plugin in the startup script to manage NoneBot using a web page? (This plugin is still under development and not recommended for production environments) No
Successfully created project onanibot
[?] Do you want to create a virtual environment? Yes
Creating a virtual environment in C:\afbot\onanibot\.venv
Successfully created virtual environment
[?] Do you need to modify or clear the PyPI mirror source configuration of pip? No
[?] Do you want to install project dependencies immediately? Yes
Installing project dependencies
Dependency installation successful
[?] Please select the built-in plugins to enable
Project configuration completed, start using it!
  1. After creating the project, start it: nb run.

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

  1. Test by sending /ping.

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

Plugin directory: YourBot/src/plugins.

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