我正在尝试发出机器人电报,但它引发Nameerror,在线异常
bot = telebot.TeleBot("754102396:AAEpwiIrfb57pZ-8EKsHj30C1LQoWCIpqbI")
说telebot is not define
我尝试卸载telebot
和PyTelegramBotAPI
,然后通过PyTelegramBotAPI==2.2.3
安装pip
,但情况变得更糟。所以我撤消了更改。
这是代码,希望您能为我提供帮助:
from telebot import TeleBot
bot = telebot.TeleBot("754102396:AAEpwiIrfb57pZ-8EKsHj30C1LQoWCIpqbI")
@bot.message_handler(commands = ["help", "start"])
def enviar_mensaje(message):
bot.reply_to(message, "Hola, soy un bot")
@bot.message_handler(func=lambda message: True)
def message(message):
bot.reply_to(message, message.text)
bot.polling()
答案 0 :(得分:1)
将此行更改为
bot = telebot.TeleBot("754102396:AAEpwiIrfb57pZ-8EKsHj30C1LQoWCIpqbI")
到
bot = TeleBot("754102396:AAEpwiIrfb57pZ-8EKsHj30C1LQoWCIpqbI")