Skip to content

restrictChatMember

限制聊天成员的权限。

请求

POST /:token/restrictchatmember

参数

参数类型必填描述
chat_idInteger/String目标聊天的唯一标识符或用户名
user_idInteger目标用户的唯一标识符
permissionsChatPermissions用户的新权限对象
until_dateInteger限制截止时间的 Unix 时间戳。若为 0 或不设置,则永久限制。限制时间少于 30 秒或多于 366 天将被视为永久限制

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>/restrictchatmember" \
  -H "Content-Type: application/json" \
  -d '{
    "chat_id": -1001234567890,
    "user_id": 987654321,
    "permissions": {
      "can_send_messages": false,
      "can_send_media_messages": false,
      "can_send_polls": false,
      "can_send_other_messages": false,
      "can_add_web_page_previews": false,
      "can_change_info": false,
      "can_invite_users": false,
      "can_pin_messages": false
    }
  }'

临时限制用户(仅允许发送文本消息,持续 24 小时)

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