Skip to content

banChatMember

Ban a user from the chat.

Request

POST /:token/banchatmember

Parameters

ParameterTypeRequiredDescription
chat_idInteger/StringYesUnique identifier or username of the target chat
user_idIntegerYesUnique identifier of the user to be banned
until_dateIntegerNoUnix 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

CodeDescription
400Bad request parameters, such as missing chat_id or user_id
401Invalid or expired token
403Bot does not have administrator privileges or permission to ban users
404Chat or user not found
500Internal 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
  }'