【发布时间】:2022-10-12 22:16:30
【问题描述】:
下面是我的电报机器人代码。 我正在尝试从用户那里获取输入并最终返回,我将为我的 ML 模型提供输入:
def chat(s):
return s
def handle_message(update: Update, context: CallbackContext):
print("inside")
tx = update.message.text
re = chat(tx)
update.message.reply_text(re)
def main():
updater = Updater("API_KEY",use_context=True)
dp = updater.dispatcher
dp.add_handler(CommandHandler(Filters.text,handle_message))
dp.add_error_handler(error)
updater.start_polling()
updater.idle()
这是我得到的错误:
File "C:\Users\NAMIT\AppData\Local\Programs\Python\Python39\lib\site- packages\telegram\ext\commandhandler.py", line 161, in __init__
self.command = [x.lower() for x in command]
TypeError: '_Text' object is not iterable
【问题讨论】:
-
欢迎来到 StackOverflow。请收下tour,学习How to Ask。为了获得帮助,您需要提供minimal reproducible example。
-
始终将有问题的完整错误消息(从“Traceback”一词开始)(不在 cmets 中)作为文本(不是屏幕截图,不链接到外部门户)。完整的错误/回溯中还有其他有用的信息。