简体   繁体   中英

How delete all message in telegram chat? (python, telegram.ext)

I encountered the problem of deleting all messages (including messages from the bot itself) in the telegram chat. How i can do this? I use the telegram.ext library.

Telegram Bot API doesn't have methods to delete multiple messages. You have to know message_id to delete it.

python-telegram-bot library has support to only Bot API. You can make use of telethon library which supports Telegram API.

There is a delete_message method in the bot object, as described in the python-telegram-bot Documentation

Example:

bot.delete_message(chat_id=message.chat_id,
               message_id=message.message_id,
               *args,
               **kwargs)

Remember that there are some limitations:

  1. A message can only be deleted if it was sent less than 48 hours ago.

  2. Bots can delete outgoing messages in groups and supergroups.

  3. If the bot is an administrator of a group, it can delete any message there

  4. If the bot has can_delete_messages permission in a supergroup or a the channel, it can delete any message there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM