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

编程入门 行业动态 更新时间:2024-10-23 11:22:07
本文介绍了我正在用 python 写一个电报机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我想通过 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屋!

更多推荐

[db:关键词]

本文发布于:2023-05-01 07:10:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1405893.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:电报   机器人   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!