如何删除电报机器人自己的消息?

问题描述

我想要实现的是,在通过bot XI发布新消息之前,请删除同一bot X所发布的先前消息。我正在研究方法bot.delete_message,但这需要{{1} }这意味着我需要在本地存储ID。有没有办法解决?像获取机器人自己的消息一样?

解决方法

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?")