deleteMessages
Delete multiple messages at once. A maximum of 100 messages can be deleted per request.
Messages are deleted individually: a few invalid message_id values (not found, already deleted, or not belonging to the chat), or messages the bot may not delete (not sent by the bot while the bot is not an administrator), will not prevent the remaining messages from being deleted.
Request
POST /:token/deletemessages
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| chat_id | Integer/String | Yes | Unique identifier for the target chat or username |
| message_ids | Integer[] | Yes | List of message identifiers to delete (maximum 100) |
| return_failed | Boolean | Optional | Pass true to receive per-message results. Defaults to false (returns true only) |
Response
Without return_failed, returns Boolean true on success, unchanged from previous versions:
{
"ok": true,
"result": true
}With return_failed: true, result contains the per-message outcome:
{
"ok": true,
"result": {
"deleted_message_ids": [101, 103],
"failed_message_ids": [
{ "message_id": 102, "description": "message to delete not found" },
{ "message_id": 104, "description": "not enough rights to delete message" }
]
}
}FailedMessageId
| Field | Type | Description |
|---|---|---|
| message_id | Integer | Identifier of the message that could not be deleted |
| description | String | Reason for the failure |
Possible values of description:
| Value | Meaning |
|---|---|
| message to delete not found | The message does not exist, was already deleted, or does not belong to the chat given by chat_id |
| not enough rights to delete message | The message was not sent by the bot, and the bot is not an administrator in that group/channel |
| chat not found | chat_id refers to neither a user nor a group/channel |
Note
The request still succeeds (ok: true) even when no message could be deleted; the reasons are reported through failed_message_ids. If you need strict "fail when the message does not exist" semantics, use the single-message deleteMessage instead.
Error Codes
| Code | Description |
|---|---|
| 400 | Bad request parameters (e.g. more than 100 entries in message_ids) |
| 401 | Invalid token |
| 403 | Bot does not have permission to perform this action (bot restricted, or group restricted) |
cURL Example
curl -X POST "https://api.safew.bot/bot<token>/deleteMessages" \
-H "Content-Type: application/json" \
-d '{
"chat_id": 123456789,
"message_ids": [101, 102, 103],
"return_failed": true
}'