File “bot.py”, line 50
if name== ‘main’:
^
SyntaxError: invalid syntax
File “bot.py”, line 46
updater.start_polling()
^
SyntaxError: invalid syntax
etc
Can you please help me with this
File “bot.py”, line 50
if name== ‘main’:
^
SyntaxError: invalid syntax
File “bot.py”, line 46
updater.start_polling()
^
SyntaxError: invalid syntax
etc
Can you please help me with this
hey @aditya.ameya ,
can you please provide a screenshot of this problem. I am not able to understand it properly.
Hi Prashant
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 = “1056264161:AAE-ZJ2SBRcXcl-kBhp38nxfjuHYg_VjciI”
def start(bot, update):
print(update)
author= updater.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 the 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)
dp = updater.dispatcher
dp.add_Handler(CommandHandler("start",start))
dp.add_Handler(CommandHandler("help",_help))
dp.add_Handler(CommandHandler("Filters.text", echo_text))
dp.add_Handler(CommandHandler("Filters.sticker", echo_sticker))
dp.add_error_Handler(CommandHandler(error)
updater.start_polling()
logger.info("polling started..")
updater.idle()
if name == “main”:
main()
The above is the code
PFA
hey @aditya.ameya,
i am not able to understand your code here.
Can you please upload it on github and share me its link. It will be easy for me to understand.
okay i will be doing it
https://github.com/aditya894/telegramchatbot.git - here is the link for github
Kindly give it a look
Regards
Aditya Bikram
you are missing a closing bracket here dp.add_error_Handler(CommandHandler(error)
( Line no. 45 ).
Just add that and it will work.
What is the actual error you are facing .
can you please provide a screenshot of it too.
hey @aditya.ameya ,
I guess this is a typo.
it should be add_handler
with small h
. Try changing that.
Okay Thank you for pointing that out
i have corrected that but i still am getting this error
Please let me know the reason , the code is updated in git
hey @aditya.ameya ,
in this line its should be MessageHandler , not CommandHandler .
Kindly have a look at the video again.