使用 python-telegram-bot 时出现错误

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

我遇到一个小问题。 初始化我的树莓派 pi4(书虫)后,以前运行的程序停止运行并给出错误。我怎样才能解决这个问题? 这是代码。

import logging
import subprocess
from telegram.ext import Updater, CommandHandler
from telegram import Update
from telegram.ext import CallbackContext
from telegram import Bot
import socket
~~~
~~~
def main() -> None:
    logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
    ip_address = get_ip_address()
    send_message(ip_address)
    updater = Updater(TOKEN, use_context=True)
    dp = updater.dispatcher
    dp.add_handler(CommandHandler("start", start))
    dp.add_handler(CommandHandler("stop", stop))
    updater.start_polling()
    updater.idle()

if __name__ == '__main__':
    main()

执行脚本后出现以下错误:

Traceback (most recent call last):
  File "/home/server/my_app/stream.py", line 52, in <module>
    main()
  File "/home/server/my_app/stream.py", line 44, in main
    updater = Updater(TOKEN, use_context=True)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Updater.__init__() got an unexpected keyword argument 'use_context'
python telegram-bot python-telegram-bot
1个回答
0
投票

你可以像这样修改你的代码。

def main() -> None:
    logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
    ip_address = get_ip_address()
    send_message(ip_address)
    updater = Updater(TOKEN)
    dp = updater.dispatcher
    dp.add_handler(CommandHandler("start", start))
    dp.add_handler(CommandHandler("stop", stop))
    updater.start_polling()
    updater.idle()

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