Skip to content

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

ParameterTypeRequiredDescription
chat_idInteger/StringYesUnique identifier for the target chat or username
message_idsInteger[]YesList of message identifiers to delete (maximum 100)
return_failedBooleanOptionalPass 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:

json
{
  "ok": true,
  "result": true
}

With return_failed: true, result contains the per-message outcome:

json
{
  "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

FieldTypeDescription
message_idIntegerIdentifier of the message that could not be deleted
descriptionStringReason for the failure

Possible values of description:

ValueMeaning
message to delete not foundThe message does not exist, was already deleted, or does not belong to the chat given by chat_id
not enough rights to delete messageThe message was not sent by the bot, and the bot is not an administrator in that group/channel
chat not foundchat_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

CodeDescription
400Bad request parameters (e.g. more than 100 entries in message_ids)
401Invalid token
403Bot does not have permission to perform this action (bot restricted, or group restricted)

cURL Example

bash
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
  }'