我搜索了它,并向 AI 询问,我注意到问题是因为 python-telegram-bot 12 库之后的新版本。
所以他们中的一些人说,只需删除使用上下文即可,但我做到了,但我不知道出了什么问题。这是代码。我是从 YouTube 上的一个视频学到的,可能有点旧了。
import constants as keys
from telegram.ext import *
import responses as R
print('Bot starting ... ')
def start_command(update, context):
update.message.reply('type something random so')
def help_command(update, context):
update.message.reply('this is my help command.')
def handle_message(update, context):
text = str(update.message.text).lower()
Response = R.sample_responses(text)
update.message.reply_text(response)
def error(update, context):
print(f'Update {update} caused error {context.error}')
# most important function most important function
def main():
##### this line is my error
updater = Updater(keys.API_KEY)
# before removing using-context:
# updater = Updater(keys.API_KEY, using-context=True)
dp = updater.dispatcher
dp.add_handler(CommandHandler("start", start_command))
dp.add_handler(CommandHandler("help", help_command))
dp.add_handler(MessageHandler(Filters.text, handle_message))
dp.add_error_handler(error)
updater.start_polling()
updater.idle()
print("polling ... ")
main()
所以使用上下文时出现错误:
File "/storage/emulated/0/1_code/someall/telegram/python/1/main.py", line 27
updater = Updater(keys.API_KEY, using-context=True)
^^^^^^^^^^^^^^
SyntaxError: expression cannot contain assignment, perhaps you meant "=="?
所以当我删除 using-context 时这是错误的:
Traceback (most recent call last):
File "/storage/emulated/0/1_code/someall/telegram/python/1/main.py", line 42, in <module>
main()
File "/storage/emulated/0/1_code/someall/telegram/python/1/main.py", line 27, in main
updater = Updater(keys.API_KEY)
^^^^^^^^^^^^^^^^^^^^^
TypeError: Updater.__init__() missing 1 required positional argument: 'update_queue'
尝试代替“using-context=True” 用这个
use_context=True