简体   繁体   中英

how to delete all messages in telegram chat with python

I am writing a telegram bot in python. One of my bot functionalities is to delete all of the messages in the chat. I find the function bot.delete_message however it delete only one message according to message id and I don't have the ids for every message.

I also saw in the telegram api some functions that can help me, like https://core.telegram.org/method/channels.deleteHistory or https://core.telegram.org/method/messages.getHistory (will allow me to get the id of every message and then delete them). but I don't see how I can call these functions in the python api.

Is there a way to call these functions with the python api? or perhaps is there another way to delete entire chat history?

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

The methods which you've mentioned in the question are not part of Telegram Bot API, but they're part of Telegram API. python-telegram-bot library has support to only Bot API. You can make use of telethon library which supports Telegram API.

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