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",
            "Port": 8080,
            "Suffix": "/onebot/v11/ws",
            "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 super user, the super user 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 it,
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 ensure that this port number is the same as the connection end configuration or related to the port mapping configuration
[?] Enter > 8080
[?] Release a shortcut startup script in the project directory? Yes
[?] Redirect the storage path of the localstore plugin to the project path for subsequent migration of the Bot? Yes
[?] Use the super user Ping command to reply to the plugin? Yes
[?] Install the logpile plugin to provide logging to file functionality? Yes
[?] Use the webui plugin to start the project in the startup script to manage NoneBot using a web page? (This plugin is still under development and is not recommended for production environments) No
Successfully created project onanibot
[?] 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
[?] 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 it 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.