ImportError: cannot import name 'Filters' from 'telegram.ext'
Asked Answered
S

3

16

I have installed python-telegram-bot like this:

pip install python-telegram-bot

And when I'm trying to do this:

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

I get this error:

ImportError: cannot import name 'Filters' from 'telegram.ext' (/home/mobitnlh/virtualenv/db_application/3.8/lib/python3.8/site-packages/telegram/ext/__init__.py)
Solberg answered 12/1, 2023 at 10:47 Comment(1)
Does this answer your question? Unable to run Python Telegram Bot Package - ErrorPelmas
T
35

They made some changes, please see the link https://docs.python-telegram-bot.org/en/stable/telegram.ext.filters.html

Instead of

from telegram.ext import Filters

do

from telegram.ext import filters

and instead of Filters.all do filters.ALL

I hope it helps!

Tressietressure answered 16/1, 2023 at 19:15 Comment(1)
from telegram.ext import filters as FiltersLublin
S
4

According to their wiki, the name is filters. So just replace Filters with filters:

from telegram.ext import Updater, CommandHandler, MessageHandler, filters, CallbackContext
Sapowith answered 12/1, 2023 at 11:21 Comment(0)
R
-1

Removed the Filters class. you can use directly attributes/classes of the filters module.

Filter classes which are ready for use, e.g Filters.all are now capitalized, e.g filters.ALL

below link is includes all :

https://docs.python-telegram-bot.org/en/v20.7/telegram.ext.filters.html

Riles answered 7/12, 2023 at 10:56 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.