OneBot icon

OneBot

Consume OneBot API

Overview

This node interacts with the OneBot API to manage group-related operations in a chat environment. Specifically, for the "群组" (Group) resource and the "设置群管理员" (Set Group Admin) operation, it allows the group owner to assign or revoke administrator privileges for group members. This is useful in scenarios where the group owner wants to delegate management responsibilities to trusted members without transferring ownership.

Practical examples include:

  • Automatically promoting active or trusted members to administrators based on certain criteria.
  • Revoking admin rights from members who no longer should have elevated permissions.
  • Managing group roles programmatically as part of a larger workflow involving group moderation or automation.

Properties

Name Meaning
Group Name or ID Select the group you own (only the group owner can set administrators).
Member Name or ID Select the group member to be set or unset as an administrator. You can search by nickname or QQ number, or input QQ number directly. Only ordinary members can be promoted or demoted.
Enable Admin Boolean flag indicating whether to set (true) or cancel (false) administrator status. Only the group owner can perform this action.

Output

The node outputs JSON data representing the response from the OneBot API for the performed operation. The structure depends on the specific API endpoint called but generally includes success status and any relevant data returned by the API.

If an error occurs during execution, the output JSON will contain an error field with the error message and a success field set to false.

No binary data output is involved in this operation.

Dependencies

  • Requires connection to the OneBot API via an API key credential configured in n8n.
  • The node uses several internal helper methods to fetch lists such as owned groups and group members dynamically.
  • The bot must have appropriate permissions in the target group, specifically ownership, to set or remove administrators.
  • The node performs permission checks by querying the bot's role in the group before executing sensitive operations.

Troubleshooting

  • Common Issues:

    • Attempting to set or remove an admin when the bot is not the group owner will fail.
    • Providing invalid or empty group IDs or user IDs will cause errors.
    • Network or API request failures may occur if the OneBot API is unreachable or credentials are invalid.
  • Error Messages:

    • "无法执行操作: 设置管理员需要群主权限,当前机器人不是群 {group_id} 的群主"
      Means the bot is not the group owner and cannot set admins. Ensure the bot account owns the group.
    • "操作需要有效的群ID,但未提供"
      Indicates that a required group ID parameter was missing.
    • Other API request errors will be logged and returned in the output's error field.
  • Resolution Tips:

    • Verify the bot's role in the group using other node operations like "Get Group Member Info".
    • Confirm that the group ID and user ID inputs are correct and correspond to existing entities.
    • Check API credentials and network connectivity.

Links and References

Discussion