delete_chat_history()#

Client.delete_chat_history()#

Deletes all messages in the chat. For group chats this will release the usernames and remove all members.

Usable by Users Bots
Parameters:
  • chat_id (int | str) – Unique identifier (int) or username (str) of the target chat.

  • max_id (int, optional) – Maximum ID of message to delete. Defaults to 0.

  • revoke (bool, optional) – Pass True to delete messages for all chat members. Always True if using in CHANNEL and SUPERGROUP chats.

  • just_clear (bool, optional) – Pass True to clear history for the current user, without actually removing chat. For PRIVATE and GROUP chats only.

  • min_date (datetime, optional) – The minimum date of the messages to delete. Delete all messages newer than this time. For PRIVATE and GROUP chats only.

  • max_date (datetime, optional) – The maximum date of the messages to delete. Delete all messages older than this time. For PRIVATE and GROUP chats only.

Returns:

int – Amount of affected messages

Example

# Delete all messages in channel
await app.delete_chat_history(chat_id, revoke=True)