我遇到了 telegram.ext.filters 没有属性“文本”的问题

问题描述 投票:0回答:1

我正在研究 python-telegram-bot v13.7 并且模块 telegram.ext.filters 没有属性“text” 这是代码:


    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()

我也尝试过Filters.text和filters.Text 我试图知道 telegram.ext.filters 是否有“文本”,这就是我所看到的there is no ,然后我尝试重新安装、升级和降级,但没有什么新内容 那么如何修复呢?

 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'
python python-3.x python-telegram-bot
1个回答
0
投票

您已经安装了 13.7 版

python-telegram-bot
,但正在使用
filters
模块,就像安装了 20 或更高版本一样。
filters
模块的 v13.7 文档可在此处获取。请注意,PTB 团队没有借用者为 v20 之前的版本提供支持,我鼓励您使用转换指南更新到最新版本。


免责声明:我目前是

python-telegram-bot
的维护者。

© www.soinside.com 2019 - 2024. All rights reserved.