当我运行下面的代码时,会显示以下错误消息:'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上写的。我想做一个能贴标签的电报机器人
这听起来像是版本控制问题。我在谷歌上搜索了一下(在这里问这个问题之前,你应该这样做),并找到了这个错误消息的许多实例。大多数都指向使用了错误版本的
PyTelegramBotAPI
模块。这是一篇来自某个人的帖子,似乎与你的问题完全相同:还有其他的点击提示了同样的修复方法。还有一个问题:
这似乎是解决你问题的另一条途径
要了解更多信息,只需在谷歌上搜索这个问题的标题
是的
然后
然后
现在它可以工作了
PyAPI 3.0有很多变化,3.0 API文档还没有出现。在制品。改用2.2.3旧版本,并确保您没有任何其他机器人api,如telebot
请尝试以下代码:
相关问题 更多 >
编程相关推荐