首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“TeleBot”对象没有属性“message_handler”

“TeleBot”对象没有属性“message_handler”
EN

Stack Overflow用户
提问于 2020-11-22 15:40:35
回答 7查看 16.9K关注 0票数 1

当我运行下面的代码时,显示以下错误消息:'TeleBot' object has no attribute 'message_handler'

代码语言:javascript
复制
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上写的。我想做一个能贴上标签的电报机器人。

EN

回答 7

Stack Overflow用户

发布于 2021-10-10 05:54:25

尝试以下代码:

代码语言:javascript
复制
pip3 uninstall telebot
pip3 uninstall PyTelegramBotAPI
pip3 install pyTelegramBotAPI
pip3 install --upgrade pyTelegramBotAPI
票数 8
EN

Stack Overflow用户

发布于 2021-02-25 19:01:10

我做到了

pip3卸载远程机器人

然后

pip3卸载PyTelegramBotAPI

然后

pip3 install PyTelegramBotAPI==2.2.3

现在它起作用了!

API3.0有很多变化,而PyTelegramBotAPI文档还没有出现。在制品。改为使用2.2.3旧版本,并确保您没有任何其他机器人api,如telebot

票数 4
EN

Stack Overflow用户

发布于 2020-11-23 01:50:46

这听起来像是一个版本控制问题。我在谷歌上搜索了一下(在这里问这个问题之前你应该已经做过了),发现了这个错误消息的很多例子。他们中的大多数都指出使用了错误版本的PyTelegramBotAPI模块。这里有一个帖子,来自一个看起来和你有完全相同问题的人:

https://www.pythonanywhere.com/forums/topic/26658/

还有其他的热门文章也提出了同样的解决方法。还有一个这样的问题:

I'm writing a telegram bot with python

这似乎是一条解决你问题的不同途径。

要了解更多信息,只需在谷歌上搜索这个问题的标题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64951712

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档