0
import logging
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters

logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', 
    level=logging.INFO)
logger = logging.getLogger(__name__)

TOKEN = "xxxxxxxxxxxxxxxxxx"



def start(bot, update):
    print(update)
    author = update.message.from_user.first_name
    reply = "Hi! {}".format(author)
    bot.send_message(chat_id=update.message.chat_id, text=reply)

def _help(bot, update):
    help_txt = "Hey! This is a help text."
    bot.send_message(chat_id = update.message.chat_id, text=help_txt)

def echo_text(bot, update ):
    reply=update.message.text
    bot.send_message(chat_id=update.message.chat_id, text=reply)

def echo_sticker(bot, update ):
    bot.send_sticker(chat_id=update.message.chat_id, sticker=update.message.sticker.file_id)


def error(bot, update):
    logger.error("Update '%s' caused error '%s'", update, update.error) 

def main():
    updater=Updater(TOKEN, use_context=True)

    dp=updater.dispatcher

    dp.add_handler(CommandHandler("start",start))
    dp.add_handler(CommandHandler("help", _help))
    dp.add_handler(MessageHandler(Filters.text, echo_text))
    dp.add_handler(MessageHandler(Filters.sticker, echo_sticker))
    dp.add_error_handler(error)


    updater.start_polling()
    logger.info("STARTED POLLING...")
    updater.idle()
if __name__ == '__main__':
    main()

Error shown is: 2020-06-30 09:20:00,924 - main - ERROR - Update '<telegram.ext.callbackcontext.CallbackContext object at 0x00000188F64EC0C8>' caused error ''CallbackContext' object has no attribute 'message''

  • 1
    Can you post the error also which you're getting? – Sanket Singh Jun 30 '20 at 16:31
  • Does this answer your question? [python-telegram-bot ERROR 'CallbackContext' object has no attribute 'message'](https://stackoverflow.com/questions/60804083/python-telegram-bot-error-callbackcontext-object-has-no-attribute-message) – Palash Goel Jun 30 '20 at 18:04
  • Error shown is: 2020-06-30 09:20:00,924 - main - ERROR - Update '' caused error ''CallbackContext' object has no attribute 'message'' – Mahima Agrawal Jul 01 '20 at 12:39
  • No Palash, it is not working. Its keep giving me the same error. – Mahima Agrawal Jul 01 '20 at 12:40

0 Answers0