1

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

Rascal
  • 31
  • 1
  • 2
  • 2
    Does this answer your question? [Unable to run Python Telegram Bot Package - Error](https://stackoverflow.com/questions/75064123/unable-to-run-python-telegram-bot-package-error) – CallMeStag Jan 12 '23 at 20:20

3 Answers3

2

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

Leonardo Rignanese
  • 865
  • 11
  • 22
1

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

Shashi
  • 565
  • 5
  • 8
-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)]
)
lewisemann
  • 19
  • 3