我正在用 python 写一个电报机器人 [英] I'm writing a telegram bot with python

查看:39
本文介绍了我正在用 python 写一个电报机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过 Python 编写一个电报机器人,但它不起作用.

I want to write a telegram bot via Python, but it doesn't work.

import telebot

bot = telebot.TeleBot("my_token")

@bot.message_handler(content_types=['text'])
def sending(message):
    bot.send_message(message.chat.id, message.text)


# RUN

bot.polling(non_stop=True)


返回给我以下问题.

AttributeError: 'TeleBot' 对象没有属性 'message_handler'

AttributeError: 'TeleBot' object has no attribute 'message_handler'

推荐答案

不幸的是,这是一个常见问题.我猜您将 lib 安装为pip install telebot",这会导致另一个包.您需要卸载telebot,安装pytelegrambotapi,但在代码中保留import telebot".

This is a common issue, unfortunately. I guess you installed the lib as "pip install telebot", which leads to another package. You need to uninstall telebot, install pytelegrambotapi, but leave "import telebot" in code.

这篇关于我正在用 python 写一个电报机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆