我正在用 python 编写一个电报机器人

Արմ*_*յան 2 python telegram telegram-bot

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

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)


Run Code Online (Sandbox Code Playgroud)

返回给我以下问题。

AttributeError:“TeleBot”对象没有属性“message_handler”

Gro*_*sha 6

不幸的是,这是一个常见问题。我猜你将库安装为“pip install telebot”,这会导致另一个包。您需要卸载 telebot,安装pytelegrambotapi,但在代码中保留“导入 telebot”。