当我运行下面的代码时,显示以下错误消息:'TeleBot' object has no attribute 'message_handler'。
import telebot
from telebot import types
keyboard1 = telebot.types.ReplyKeyboardMarkup()
keyboard1.row('Ok', 'Bye')
bot = telebot.TeleBot('API')
@bot.message_handler(commands=['start'])
def start_message(message):
bot.send_message(message.chat.id, 'Hi what do you want /start', reply_markup=keyboard1)
@bot.message_handler(content_types=['text'])
def send_text(message):
if message.text.lower() =='Hello':
bot.send_message(message.chat.id, message.text.upper() )
elif message.text.lower() =='Bye':
bot.send_message(message.chat.id,'see you soom' )
elif message.text.lower() == 'I love you':
bot.send_sticker(message.chat.id, 'API')
@bot.message_handler(content_types=['sticker'])
def sticker_id(message):
print(message)
bot.polling(none_stop=True)那么到底出了什么问题呢?我已经安装了pip和其他工具。我在python IDLE上写的。我想做一个能贴上标签的电报机器人。
发布于 2021-10-10 05:54:25
尝试以下代码:
pip3 uninstall telebot
pip3 uninstall PyTelegramBotAPI
pip3 install pyTelegramBotAPI
pip3 install --upgrade pyTelegramBotAPI发布于 2021-02-25 19:01:10
我做到了
pip3卸载远程机器人
然后
pip3卸载PyTelegramBotAPI
然后
pip3 install PyTelegramBotAPI==2.2.3
现在它起作用了!
API3.0有很多变化,而PyTelegramBotAPI文档还没有出现。在制品。改为使用2.2.3旧版本,并确保您没有任何其他机器人api,如telebot
发布于 2020-11-23 01:50:46
这听起来像是一个版本控制问题。我在谷歌上搜索了一下(在这里问这个问题之前你应该已经做过了),发现了这个错误消息的很多例子。他们中的大多数都指出使用了错误版本的PyTelegramBotAPI模块。这里有一个帖子,来自一个看起来和你有完全相同问题的人:
还有其他的热门文章也提出了同样的解决方法。还有一个这样的问题:
这似乎是一条解决你问题的不同途径。
要了解更多信息,只需在谷歌上搜索这个问题的标题。
https://stackoverflow.com/questions/64951712
复制相似问题