如何使用python删除电报聊天中的所有消息

时间:2020-03-31 17:43:01

标签: python telegram telegram-bot python-telegram-bot

我正在用python写一个电报机器人。 我的漫游器功能之一是删除聊天中的所有消息。我找到了函数bot.delete_message,但是它根据消息ID仅删除一条消息,而我没有每条消息的ID。

我还在电报api中看到了一些可以帮助我的功能,例如https://core.telegram.org/method/channels.deleteHistoryhttps://core.telegram.org/method/messages.getHistory(将允许我获取每条消息的ID,然后将其删除)。但我看不到如何在python API中调用这些函数。

是否可以使用python API调用这些函数?也许还有另一种删除整个聊天记录的方法?

1 个答案:

答案 0 :(得分:0)

Telegram Bot API没有删除多个消息的方法。您必须知道message_id才能将其删除。

您在问题中提到的方法不属于Telegram Bot API,但属于Telegram API。 python-telegram-bot库仅支持Bot API。您可以使用支持电报API的telethon库。