restrictChatMember
Restrict a chat member's permissions.
Request
POST /:token/restrictchatmember
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| chat_id | Integer/String | Yes | Unique identifier or username of the target chat |
| user_id | Integer | Yes | Unique identifier of the target user |
| permissions | ChatPermissions | Yes | New permissions for the user |
| until_date | Integer | No | Unix timestamp for the restriction expiration date. If set to 0 or omitted, the user is restricted permanently. Restrictions shorter than 30 seconds or longer than 366 days are treated as permanent |
ChatPermissions Object
| Field | Type | Description |
|---|---|---|
| can_send_messages | Boolean | Whether the user is allowed to send text messages, contacts, locations, and venues |
| can_send_media_messages | Boolean | Whether the user is allowed to send audio, documents, photos, videos, video notes, and voice notes |
| can_send_polls | Boolean | Whether the user is allowed to send polls |
| can_send_other_messages | Boolean | Whether the user is allowed to send animations, games, stickers, and use inline bots |
| can_add_web_page_previews | Boolean | Whether the user is allowed to add web page link previews |
| can_change_info | Boolean | Whether the user is allowed to change the chat title, photo, and other settings |
| can_invite_users | Boolean | Whether the user is allowed to invite new users to the chat |
| can_pin_messages | Boolean | Whether the user is allowed to pin messages |
Response
Returns Boolean true on success.
json
{
"ok": true,
"result": true
}Error Codes
| Code | Description |
|---|---|
| 400 | Bad request parameters, such as missing required parameters or invalid permissions format |
| 401 | Invalid or expired token |
| 403 | Bot does not have administrator privileges or permission to restrict members |
| 404 | Chat or user not found |
| 500 | Internal server error |
Example
cURL
Mute a user (restrict all messages)
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
}
}'Temporarily restrict a user (allow text messages only, for 24 hours)
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
}'