python - 在创建 Telegram Bot 时,我应该怎么做才能防止 python 给出“更新”的名称错误?
问题描述
当我试图从用户那里获取我的电报机器人的输入时,我遇到了这个错误消息。谢谢你的帮助。
Traceback (most recent call last):
bot.polling()
File "C:\Users\AppData\Local\Programs\Python\Python39\lib\site-packages\pytelegrambotapi-3.8.1-py3.9.egg\telebot\__init__.py", line 620, in polling
File "C:\Users\AppData\Local\Programs\Python\Python39\lib\site-packages\pytelegrambotapi-3.8.1-py3.9.egg\telebot\__init__.py", line 679, in __threaded_polling
File "C:\Users\AppData\Local\Programs\Python\Python39\lib\site-packages\pytelegrambotapi-3.8.1-py3.9.egg\telebot\__init__.py", line 642, in __threaded_polling
File "C:\Users\AppData\Local\Programs\Python\Python39\lib\site-packages\pytelegrambotapi-3.8.1-py3.9.egg\telebot\util.py", line 130, in raise_exceptions
File "C:\Users\AppData\Local\Programs\Python\Python39\lib\site-packages\pytelegrambotapi-3.8.1-py3.9.egg\telebot\util.py", line 82, in run
File "C:\Users\Desktop\CalendarGo\Main.py", line 22, in set
user_input = update.message.text
NameError: name 'update' is not defined
import os
import telebot
from telebot.types import Update
from telegram.ext import Updater, Filters, CommandHandler, MessageHandler
API_KEY = "API_KEY"
bot = telebot.TeleBot(API_KEY)
@bot.message_handler(commands=["Set"])
def set(message):
bot.send_message(message.chat.id, "Please enter the word")
user_input = update.message.text
update.message.reply_text(do_something(user_input))
def do_something(user_input):
answer = "You have wrote me " + user_input
return answer
bot.polling()
解决方案
推荐阅读
- ruby-on-rails - Rails 事务启动钩子
- javascript - 需要帮助在 REST api 的 GET 函数中将 json 数据写入 json 文件
- reactjs - 我想使用与 ant design 的反应来验证密码
- python - Matplotlib 命令不起作用
- internet-explorer - 卡引导程序 4.1 在 Internet Explorer 中不起作用
- android - 强制页面加载到 webview 中,而不是外部浏览器保持低 API lvl
- python - 无法在 Windows 10 上的 Anaconda 3.6 中导入张量流
- python - windows平台上python 3中从.ui到.py的转换
- sql - SQL中带有条件的ROUNDUP函数
- ckeditor5 - 如何在 CKEditor 5 中更新元素()?