skip to Main Content

states={
MOB_NO: [MessageHandler(filters.text, reply_to)],

},

AttributeError: module ‘telegram.ext.filters’ has no attribute ‘text’

I install pip install python-telegram-bot.

And here we import module.
from telegram.ext import (Updater, CommandHandler, MessageHandler, filters,
ConversationHandler)

When we handle messages it says.

AttributeError: module ‘telegram.ext.filters’ has no attribute ‘text

3

Answers


  1. try using this one

    from telegram.ext import filters
    
    start_handler = ConversationHandler(
        entry_points=[CommandHandler("start", start)],
        states= {
            "ONE": [MessageHandler(filters.TEXT, one)],
            "TWO": [MessageHandler(filters.TEXT, two)],
        },
        fallbacks=[CommandHandler("cancel", start)]
    )
    
    Login or Signup to reply.
  2. Most probably you are using the latest version package. Downgrade the python-telegram-bot version to 13.7.

     pip install python-telegram-bot==13.7 --force-reinstall
    

    And use "Filters" with capital F

    Login or Signup to reply.
  3. From version 20 of python-telegram-bot, the filters library is lowercase and the single filters are written all uppercase.

    So until v13.7 we had Filters.text, but from v20 it became filters.TEXT.

    Maybe in your requirements.txt file you have python-telegram-bot>=13.4, so either you change it to python-telegram-bot==13.7, or you need to update your code.

    Note that this applies also to the import, until v13.7: from telegram.ext import Filters becomes telegram.ext import filters.

    Source: https://github.com/python-telegram-bot/python-telegram-bot/wiki/Transition-guide-to-Version-20.0

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search