首页 资讯 下载 教程 Skills 社群

OpenClaw 聊天命令系统:/命令、Shell 执行与权限控制

命令配置

openclaw.json 中通过 commands 字段控制聊天命令行为:

{
  commands: {
    native: "auto",       // 平台原生命令注册
    text: true,           // 解析 /commands 文本命令
    bash: false,          // 是否允许 ! shell 执行
    bashForegroundMs: 2000,
    config: false,        // 是否允许 /config 读写
    debug: false,         // 调试命令
    restart: false        // 重启命令
  }
}

参数说明

  • native"auto" 会自动在 Discord 和 Telegram 上注册原生斜杠命令菜单;false 清除已注册的命令
  • text:解析聊天消息中的 /命令 格式
  • bash:允许通过 ! <命令> 在宿主机上执行 Shell 命令(需同时启用 tools.elevated.enabled
  • config:允许通过 /config 命令读写配置

命令权限控制

通过 allowFrom 限制谁可以使用命令:

{
  commands: {
    allowFrom: {
      "*": ["user1"],
      discord: ["user:123"],
      slack: ["U456"]
    },
    useAccessGroups: true
  }
}
  • "*" 表示所有频道的默认规则
  • 可以按频道类型单独配置
  • 设置 allowFrom 后,频道自身的 allowlist 和配对验证会被绕过
  • useAccessGroups: false 可以让命令绕过访问组策略

按频道自定义

不同频道可以独立控制命令行为:

{
  channels: {
    discord: {
      commands: { native: true }   // Discord 注册原生斜杠命令
    },
    telegram: {
      customCommands: [            // Telegram Bot 菜单额外命令
        { command: "help", description: "获取帮助" },
        { command: "status", description: "查看状态" }
      ]
    }
  }
}

常用内置命令

命令 功能
/new/reset 重置当前会话
/config 查看或修改配置
/btw <消息> 侧对话(不影响主上下文)
! <shell命令> 执行 Shell 命令(需启用 bash)