Aru*_*han 4 python telegram-bot
当我运行下面的代码时,显示以下错误消息:'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)
Run Code Online (Sandbox Code Playgroud)
那么有什么问题吗?我已经安装了 pip 和其他。我是在 python IDLE 上写的。我想制作一个可以提供贴纸的电报机器人。
小智 15
试试这个代码:
pip3 uninstall telebot
pip3 uninstall PyTelegramBotAPI
pip3 install pyTelegramBotAPI
pip3 install --upgrade pyTelegramBotAPI
Run Code Online (Sandbox Code Playgroud)
我做到了
pip3 uninstall telebot
Run Code Online (Sandbox Code Playgroud)
然后
pip3 uninstall PyTelegramBotAPI
Run Code Online (Sandbox Code Playgroud)
进而
pip3 install PyTelegramBotAPI==2.2.3
Run Code Online (Sandbox Code Playgroud)
现在可以了!
PyTelegramBotAPI 3.0 有很多变化,3.0 API 文档还没有。在制品。请使用 2.2.3 旧版本,并确保您没有任何其他机器人 api,例如 telebot