deleteMessages
批量删除消息,最多 100 条。
逐条删除:其中某几条 message_id 无效(不存在、已删除、不属于该会话),或 bot 无权删除(消息不是 bot 发的,且 bot 不是管理员),都不会阻止其余消息被删除。
请求
POST /:token/deletemessages
参数
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| chat_id | Integer/String | 是 | 目标聊天 ID |
| message_ids | Integer[] | 是 | 要删除的消息 ID 列表(最多 100 条) |
| return_failed | Boolean | 否 | 为 true 时返回逐条删除结果,默认 false(只返回 true) |
响应
不传 return_failed 时,成功返回 Boolean 值 true,与旧版本一致:
json
{
"ok": true,
"result": true
}传 return_failed: true 时,result 返回逐条结果:
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
| 字段 | 类型 | 描述 |
|---|---|---|
| message_id | Integer | 删除失败的消息 ID |
| description | String | 失败原因 |
description 的取值:
| 取值 | 含义 |
|---|---|
| message to delete not found | 消息不存在、已被删除,或不属于 chat_id 指定的会话 |
| not enough rights to delete message | 消息不是 bot 发的,且 bot 在该群组/频道不是管理员 |
| chat not found | chat_id 既不是用户也不是群组/频道 |
注意
一条消息都没删成时接口仍返回成功(ok: true),失败原因通过 failed_message_ids 给出。 如果需要「消息不存在就报错」的严格语义,请改用单条删除的 deleteMessage。
错误码
| 错误码 | 描述 |
|---|---|
| 400 | 请求参数错误(如 message_ids 超过 100 条) |
| 401 | Token 无效 |
| 403 | 无权限执行此操作(bot 被禁言,或群组受限) |
cURL 示例
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
}'