restrictChatMember
限制聊天成员的权限。
请求
POST /:token/restrictchatmember
参数
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| chat_id | Integer/String | 是 | 目标聊天的唯一标识符或用户名 |
| user_id | Integer | 是 | 目标用户的唯一标识符 |
| permissions | ChatPermissions | 是 | 用户的新权限对象 |
| until_date | Integer | 否 | 限制截止时间的 Unix 时间戳。若为 0 或不设置,则永久限制。限制时间少于 30 秒或多于 366 天将被视为永久限制 |
ChatPermissions 对象
| 字段 | 类型 | 描述 |
|---|---|---|
| can_send_messages | Boolean | 是否允许发送文本消息、联系人、位置和场所 |
| can_send_media_messages | Boolean | 是否允许发送音频、文档、照片、视频、视频备注和语音备注 |
| can_send_polls | Boolean | 是否允许发送投票 |
| can_send_other_messages | Boolean | 是否允许发送动画、游戏、贴纸以及使用内联 Bot |
| can_add_web_page_previews | Boolean | 是否允许添加网页链接预览 |
| can_change_info | Boolean | 是否允许更改聊天标题、照片和其他设置 |
| can_invite_users | Boolean | 是否允许邀请新用户加入聊天 |
| can_pin_messages | Boolean | 是否允许置顶消息 |
响应
成功时返回 Boolean 值 true。
json
{
"ok": true,
"result": true
}错误码
| 错误码 | 描述 |
|---|---|
| 400 | 请求参数错误,如缺少必填参数或 permissions 格式不正确 |
| 401 | Token 无效或已过期 |
| 403 | Bot 没有管理员权限或没有限制成员的权限 |
| 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
}'