Skip to content

setChatPermissions

设置群组的默认权限。Bot 需要管理员权限。

请求

POST /:token/setchatpermissions

参数

参数类型必填描述
chat_idInteger/String目标聊天的唯一标识符或用户名
permissionsChatPermissions群组的默认权限对象

ChatPermissions 对象

字段类型描述
can_send_messagesBoolean是否允许发送文本消息、联系人、位置和场所
can_send_media_messagesBoolean是否允许发送音频、文档、照片、视频、视频备注和语音备注
can_send_pollsBoolean是否允许发送投票
can_send_other_messagesBoolean是否允许发送动画、游戏、贴纸以及使用内联 Bot
can_add_web_page_previewsBoolean是否允许添加网页链接预览
can_change_infoBoolean是否允许更改聊天标题、照片和其他设置
can_invite_usersBoolean是否允许邀请新用户加入聊天
can_pin_messagesBoolean是否允许置顶消息

响应

成功时返回 Boolean 值 true

json
{
  "ok": true,
  "result": true
}

错误码

错误码描述
400请求参数错误,如 permissions 格式不正确
401Token 无效或已过期
403Bot 没有管理员权限或没有修改权限的权限
404聊天不存在
500服务器内部错误

示例

cURL

bash
curl -X POST "https://api.example.com/<token>/setchatpermissions" \
  -H "Content-Type: application/json" \
  -d '{
    "chat_id": -1001234567890,
    "permissions": {
      "can_send_messages": true,
      "can_send_media_messages": true,
      "can_send_polls": false,
      "can_send_other_messages": true,
      "can_add_web_page_previews": true,
      "can_change_info": false,
      "can_invite_users": true,
      "can_pin_messages": false
    }
  }'