if update.message.parse_entities(types == links_list) >>> NameError: name 'types' is not defined (Python-Telegram-Bot)
sorry for my bad English 🙂
i wrote a telegram bot with PTB
I want to check if there is a link in the message or not
this is my code :
from telegram.ext import Updater, MessageHandler, CommandHandler, Filters from telegram import MessageEntity TOKEN = "MY TOKEN" updater = Updater(TOKEN,use_context=True) def test(update, context): #<<<< cid = update.message.chat_id foo = update.message.parse_entities links = [MessageEntity.TEXT_LINK,MessageEntity.URL] print(foo.type) if foo(type == links): context.bot.delete_message(cid,update.message.message_id) #Handlers dispatcher = updater.dispatcher dispatcher.add_handler(MessageHandler(Filters.text,test)) #Polling updater.start_polling()
I run this and I send a normal message to the robot but i get this error in terminal :
No error handlers are registered, logging exception. Traceback (most recent call last): File "/home/moein/.local/lib/python3.8/site-packages/telegram/ext/dispatcher.py", line 340, in process_update handler.handle_update(update, self, check, context) File "/home/moein/.local/lib/python3.8/site-packages/telegram/ext/handler.py", line 119, in handle_update return self.callback(update, context) File "test.py", line 12, in test if foo(types == links): NameError: name 'types' is not defined
What is the problem with this code?
Did I write this incorrectly?
If yes, what is the correct code?