-1

I am using 'python-telegram-bot' when trying to delete the previous message send by the Bot above got raised!

my code:

updater = Updater(BOT_TOKEN, use_context=True)
dispatcher = updater.dispatcher

def start (update: Update, context: CallbackContext):
    msg_info = update.message.reply_text('Hi')
    print(msg_info)
    msg_id = msg_info['message_id']
    chat_id = msg_info['chat']['id']
    from telegram import Bot
    status = Bot.delete_message(chat_id=chat_id, message_id=msg_id)
    print(status)

def handle_inputs (update: Update, context: CallbackContext):
    comd = update.message.text
    if (comd == '/start'): 
        start(update, context)
    else:
        update.message.reply_text("Sorry '%s' is not a valid command" % update.message.text)
       
def main():
    
    updater.dispatcher.add_handler(MessageHandler(Filters.text, handle_inputs))
    
    updater.start_polling()

if __name__ == '__main__':
    main()

I am new to Telegram bot. What I've tried is checking the some documentation, but still couldn't pass through the problem. I just want to delete the message which is currently send by the bot

Sain
  • 35
  • 6

1 Answers1

1

Please look at the following example.

You using the class instead the instance. Bot is a class object. You need bot = Bot('token'). bot is now an instance of type Bot. and now bot.delete_message() will work as now self is defined.

Doluk
  • 476
  • 2
  • 9
  • Man! you are a lifesaver! Thank you so much!! I've been trying to solve this from past 4 hours now. Also I've already implemented `updater`, `dispatcher`, so do I need to again pass the `Token` to `Bot` ? I mean can I do something with `updater`, `dispatcher` itself? – Sain Dec 07 '22 at 10:19