NoneBot OneBot Adapter Documentation

website·Indexed 30 days ago

https://adapter-onebot.netlify.app/

Documentation for the NoneBot OneBot protocol adapter, providing support for OneBot v11 and v12. Includes API references for adapters, event models, message segments, and configuration, as well as installation and setup guides for WebSocket connections.

Tokens
11.2K
Snippets
78
Records
132
Agent score
75%

What's inside NoneBot OneBot Adapter

  1. Overview of OneBot Protocol Adapter

    The OneBot protocol adapter provides support for both v11 and v12 versions of the OneBot protocol. For detailed protocol specifications, refer to the official OneBot documentation (onebot.dev), OneBot v11 (11.onebot.dev), and OneBot v12 (12.onebot.dev).
  2. Get channel member information

    v12
    Retrieve information about a specific member within a channel using the get_channel_member_info method. Requires the guild ID, channel ID, and user ID.
    # Example usage (async)
    response = await bot.get_channel_member_info(
        guild_id="your_guild_id",
        channel_id="your_channel_id",
        user_id="your_user_id"
    )
    # Returns GetChannelMemberInfoResp
  3. Use the Bot class to interact with OneBot v12

    v12
    The Bot class is the primary interface for interacting with a OneBot v12 implementation. It provides methods to call protocol APIs, handle events, send messages, and manage bot state.
    # Bot class constructor
    Bot(adapter, self_id, impl, platform, status=...)
  4. Retrieve user and group information

    v11

    Methods to fetch data from the OneBot adapter:

    • get_login_info: Get information about the bot account.
    • get_stranger_info: Get info for a user not in the bot's friend list.
    • get_friend_list: Retrieve the list of friends.
    • get_group_info: Get details about a specific group.
    • get_group_list: Retrieve all groups the bot is in.
    • get_group_member_info: Get details for a specific member of a group.
  5. Use ResultStore to manage OneBot API callback results

    The ResultStore class provides a mechanism for storing and fetching results from OneBot API callbacks. It allows developers to track asynchronous requests using sequence numbers (seq) and retrieve the corresponding response data.
  6. Connect OneBot V12 via HTTP Webhook

    To connect a OneBot V12 implementation using HTTP Webhook:

    1. Configure the implementation's http webhook settings and set the push address to one of the following:
    • http://<HOST>:<PORT>/onebot/v12/
    • http://<HOST>:<PORT>/onebot/v12/http
    • http://<HOST>:<PORT>/onebot/v12/http/ (Where <HOST> and <PORT> are the NoneBot configuration values).
    1. Enable the http server in the OneBot implementation to allow API calls.

    2. In the NoneBot .env file, specify the API root for the bot:

    ONEBOT_V12_API_ROOTS={"YourQQID": "http://<OB_HOST>:<OB_PORT>/"} (Where <OB_HOST> and <OB_PORT> are the OneBot implementation's HTTP server settings).

    Requirement: NoneBot must use HTTPClient and ASGI type drivers.

    ONEBOT_V12_API_ROOTS={"你的QQ号": "http://127.0.0.1:5700/"}
  7. Connect OneBot V12 via Forward WebSocket

    To connect a OneBot V12 implementation using Forward WebSocket:

    1. Configure the OneBot implementation's ws server to enable WebSocket server listening.

    2. In the NoneBot .env file, provide the WebSocket address of the bot:

    ONEBOT_V12_WS_URLS=["ws://<OB_HOST>:<OB_PORT>"] (Where <OB_HOST> and <OB_PORT> are the OneBot implementation's WebSocket server settings).

    Requirement: NoneBot must use the WebSocketClient type driver.

    ONEBOT_V12_WS_URLS=["ws://127.0.0.1:6700"]
  8. Connect OneBot V11 via Forward WebSocket

    To connect a OneBot V11 implementation using Forward WebSocket:

    1. Configure the OneBot implementation's ws server to enable WebSocket server listening.

    2. In the NoneBot .env file, provide the WebSocket address of the bot:

    ONEBOT_WS_URLS=["ws://<OB_HOST>:<OB_PORT>"] (Where <OB_HOST> and <OB_PORT> are the OneBot implementation's WebSocket server settings).

    Requirement: NoneBot must use the WebSocketClient type driver.

    ONEBOT_WS_URLS=["ws://127.0.0.1:6700"]
  9. Connect OneBot V12 via Reverse WebSocket

    To connect a OneBot V12 implementation using Reverse WebSocket (recommended), configure the implementation's ws reverse settings and set the push address to one of the following:

    • ws://<HOST>:<PORT>/onebot/v12/
    • ws://<HOST>:<PORT>/onebot/v12/ws
    • ws://<HOST>:<PORT>/onebot/v12/ws/

    Replace <HOST> and <PORT> with the values configured in NoneBot (e.g., 127.0.0.1 and 8080).

    Requirement: NoneBot must use the ASGI type driver.

  10. Connect OneBot V11 via Reverse WebSocket

    To connect a OneBot V11 implementation using Reverse WebSocket (recommended), configure the implementation's ws reverse settings and set the reporting address to one of the following:

    • ws://<HOST>:<PORT>/onebot/v11/
    • ws://<HOST>:<PORT>/onebot/v11/ws
    • ws://<HOST>:<PORT>/onebot/v11/ws/

    Replace <HOST> and <PORT> with the values configured in NoneBot (e.g., 127.0.0.1 and 8080).

    Requirement: NoneBot must be using the ReverseDriver for this connection method to work.

  11. Connect OneBot V11 via HTTP POST

    To connect a OneBot V11 implementation using HTTP POST:

    1. Configure the implementation's http post settings and set the reporting address to one of the following:
    • http://<HOST>:<PORT>/onebot/v11/
    • http://<HOST>:<PORT>/onebot/v11/http
    • http://<HOST>:<PORT>/onebot/v11/http/ (Where <HOST> and <PORT> are the NoneBot configuration values).
    1. Enable the http server in the OneBot implementation to allow API calls.

    2. In the NoneBot .env file, specify the API root for the bot:

    ONEBOT_API_ROOTS={"YourQQID": "http://<OB_HOST>:<OB_PORT>/"} (Where <OB_HOST> and <OB_PORT> are the OneBot implementation's HTTP server settings).

    Requirement: NoneBot must use HTTPClient and ASGI type drivers.

    ONEBOT_API_ROOTS={"你的QQ号": "http://127.0.0.1:5700/"}