banChatMember
Ban a user from the chat.
Request
POST /:token/banchatmember
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 user to be banned |
| until_date | Integer | No | Unix timestamp for the ban expiration date. If set to 0 or omitted, the user is banned permanently. Bans shorter than 30 seconds or longer than 366 days are treated as permanent |
Response
Returns Boolean true on success.
json
{
"ok": true,
"result": true
}Error Codes
| Code | Description |
|---|---|
| 400 | Bad request parameters, such as missing chat_id or user_id |
| 401 | Invalid or expired token |
| 403 | Bot does not have administrator privileges or permission to ban users |
| 404 | Chat or user not found |
| 500 | Internal server error |
Example
cURL
Permanently ban a user
bash
curl -X POST "https://api.example.com/<token>/banchatmember" \
-H "Content-Type: application/json" \
-d '{
"chat_id": -1001234567890,
"user_id": 987654321
}'Temporarily ban a user (24 hours)
bash
curl -X POST "https://api.example.com/<token>/banchatmember" \
-H "Content-Type: application/json" \
-d '{
"chat_id": -1001234567890,
"user_id": 987654321,
"until_date": 1700086400
}'