Error in Telegram Bot

I AM GETTING FOLLOWING ERROR WHILE RUNNING THE CODE FROM CMD:

<telegram.ext.callbackcontext.CallbackContext object at 0x000002A9103D6550>
2020-12-30 14:43:35,469 - main - ERROR - Update ‘<telegram.ext.callbackcontext.CallbackContext object at 0x000002A9103BB760>’ caused error ‘‘CallbackContext’ object has no attribute ‘message’’


I HAVE REMATCHED THE CODE, IT IS CORRECT. PLEASE TELL ME WHAT IS THE MISTAKE.
MY CODE

Using logging module to log any warnings

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

Enable logging

logging.basicConfig(format=’%(asctime)s - %(name)s - %(levelname)s - %(message)s’,
level=logging.INFO)

logger = logging.getLogger(name)
###############

TOKEN = “1421904098:AAF1RbQLM-K_3cIf7GfxbbgulQLw7i3rZd0”

By default, any function passed inside command handler will get 2 arguments which are bot and update

bot represents bot object and update represents the update which we have received

Any function which we define inside handler will take bot and update as arguments

def start(bot, update):
print(update)
author = update.message.from_user.first_name # Name of sender of the message
#msg = update.message.text # Actual message received from user
reply = “Hi! {}”.format(author) # Reply to be sent to the user
bot.send_message(chat_id=update.message.chat_id, text=reply) # Sending reply

def _help(bot, update): # To provide help to user
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): # Function to give response if a text message is received
reply = update.message.text # Since it is a echo bot, it will simply send the same message as reply which is received from user
bot.send_message(chat_id=update.message.chat_id, text=reply)

def echo_sticker(bot, update): # Function to give response if a sticker message is received
bot.send_sticker(chat_id=update.message.chat_id, sticker=update.message.sticker.file_id) # Since it is a echo bot, it will simply send the same message as reply which is received from user

def error(bot, update): # Error handler
logger.error(“Update ‘%s’ caused error ‘%s’”, update, update.error)

def main():
updater = Updater(TOKEN) # Updater object to receive updates from telegram server

dp = updater.dispatcher     # It will handle the updates like giving response on received message

# For dispatcher, we need multiple handlers to handle different situations

dp.add_handler(CommandHandler("start", start))      # If user types /start, call start() function
dp.add_handler(CommandHandler("help", _help))       # To provide help
dp.add_handler(MessageHandler(Filters.text, echo_text))     # To handle messages. We have filters to determine what type of message have we received, like, if it is text then echo_text function should be called
dp.add_handler(MessageHandler(Filters.sticker, echo_sticker))       # To handle stickers
dp.add_error_handler(error)     # For handling all kind of errors

updater.start_polling()     # To start polling
logger.info("Started polling...")
updater.idle()      # It will wait for you to press Ctrl+C to stop polling

In any telegram bot, if we put / before any query, it means it is a command

if name == “main”:
main()

Hello @vinay86048, you can check this out https://stackoverflow.com/questions/60804083/python-telegram-bot-error-callbackcontext-object-has-no-attribute-message
Pls, let me know if it doesn’t work.
Thanks :slight_smile:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.