I have trouble with telegram.ext.filters has not have attribute "text"

60 Views Asked by At

I'm working on python-telegram-bot v13.7 and module telegram.ext.filters has not have attribute "text" this is code:

import logging
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
import telegram.ext.filters as Filters
import openai
import urllib3


openai.api_key = 'token openai'

logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
                    level=logging.INFO)
logger = logging.getLogger(__name__)

def start(update, context):
    update.message.reply_text('Hi I'm your personal bot')

def echo(update, context):
    user_input = update.message.text
    response = generate_response(user_input)
    update.message.reply_text(response)

def generate_response(input_text):
    response = openai.Completion.create(
        engine="text-davinci-002",
        prompt=input_text,
        max_tokens=50
    )
    return response.choices[0].text.strip()

def main():
    updater = Updater("token telegram", use_context=True )

    dispatcher = updater.dispatcher

    dispatcher.add_handler(CommandHandler("start", start))

    dispatcher.add_handler(MessageHandler(Filters.text & ~Filters.command, echo))

    updater.start_polling()

    updater.idle()

if __name__ == '__main__':
    main()

I tried Filters.text and filters.Text too I tried to know is telegram.ext.filters has "text" and it is what I seethere is no "text" attribute then I tried reinstall, upgrade and downgrade but nothing new so how it can be fixed?

 D:\R.M\Python\Lib\site-packages\telegram\utils\request.py:49: UserWarning: python-telegram-bot is using upstream urllib3. This is allowed but not supported by python-telegram-bot maintainers.
  warnings.warn(
Traceback (most recent call last):
  File "D:\R.M\piton\CHATGPTTELEGRAM.PY", line 13, in <module>
    do_stuff()
  File "D:\R.M\piton\CHATGPTTELEGRAM.PY", line 10, in do_stuff
    raise Exception("test exception")
Exception: test exception

Traceback (most recent call last):
  File "D:\R.M\piton\CHATGPTTELEGRAM.PY", line 64, in <module>
    main()
  File "D:\R.M\piton\CHATGPTTELEGRAM.PY", line 55, in main
    dispatcher.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo))
                                          ^^^^^^^^^^^^
AttributeError: module 'telegram.ext.filters' has no attribute 'TEXT'
1

There are 1 best solutions below

0
CallMeStag On

You have installed version 13.7 of python-telegram-bot but are using the filters module like you had installed version 20 or newer. The v13.7 documentation of the filters module is available here. Please note that the PTB team no longer provides support for versions older than v20 and I encourage you to update to the latest version using the transition guide.


Disclaimer: I'm currently the maintainer of python-telegram-bot.