简体   繁体   中英

Getting TypeError: delete_message() missing 1 required positional argument: 'self', when trying to delete a Bot message in Telegram Bot

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

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.

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