Telegram bot 如何删除电报bot自己的消息?

Telegram bot 如何删除电报bot自己的消息?,telegram-bot,python-telegram-bot,Telegram Bot,Python Telegram Bot,我想要实现的是,在我通过bot X发布新消息之前,我会删除由同一bot X发布的以前的消息。我正在研究方法bot.delete_message,但这需要message_id这意味着我需要存储一些本地拥有的id。这有什么办法吗?像获取机器人自己的消息一样?对我不起作用。因为脚本是由cron作业运行的,所以我无法将内容存储在内存中。最后,我将最后一条消息if存储在一个文件中,然后读取它。tellegram库中有一个方法,当用户向bot发送消息时,bot检查历史记录并接收bot发送的最后一条消息——如

我想要实现的是,在我通过bot X发布新消息之前,我会删除由同一bot X发布的以前的消息。我正在研究方法
bot.delete_message
,但这需要
message_id
这意味着我需要存储一些本地拥有的id。这有什么办法吗?像获取机器人自己的消息一样?

对我不起作用。因为脚本是由cron作业运行的,所以我无法将内容存储在内存中。最后,我将最后一条消息if存储在一个文件中,然后读取它。tellegram库中有一个方法,当用户向bot发送消息时,bot检查历史记录并接收bot发送的最后一条消息——如果没有找到消息,bot将忽略以下内容,否则接收最后一条消息删除它并发送新消息是的,但我需要bot自己的消息历史记录,这似乎是不可能的。bot没有保存消息,如果这是您的意思,除非可能。
import python-telegram....
import time

current_message = None


def current_message_updater(new_message):
    global current_message
    # delete last message
    if not current_message:
        current_message.delete()
    # send new message will return its message object,
    # we assign it into current_message variable
    new = bot.send_message(....., text=new_message)
    current_message = new


# if all of this is happening in the same function
# you can do like this

def my handler():
    message = bot.send_message(...., text="hi new user")
    time.sleep(1)
    message.delete()
    another_one = bot.send_message(..., text="How are u?")