首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用python的telebot库开发的电报机器人不会在电报频道上工作吗?

用python的telebot库开发的电报机器人不会在电报频道上工作吗?
EN

Stack Overflow用户
提问于 2021-11-25 07:42:40
回答 2查看 636关注 0票数 1

我使用telebot库构建了一个简单的电报机器人,它已经成功运行了!然后我把机器人加入一个电报频道,它不起作用了!另外,我把同一个机器人添加到一个电报组中,然后它就开始工作了!我有点搞不懂为什么电报机器人不在我的电报频道工作?有人能帮我渡过难关吗?

这是我的密码。

代码语言:javascript
运行
复制
import telebot

from constatnts import API_KEY

bot = telebot.TeleBot(API_KEY, parse_mode=None)


@bot.message_handler(commands=['help', 'hello'])
def send_help_message(msg):
    bot.reply_to(msg, "Hello this is test bot for ml5")
    print(msg)


@bot.message_handler(func=lambda msg: msg.content_type == 'text' )
def send_message(msg):
    bot.reply_to(msg, "Gotcha")

bot.polling()
EN

回答 2

Stack Overflow用户

发布于 2021-12-14 06:20:37

IIRC、消息和通道帖子有不同的处理程序:

代码语言:javascript
运行
复制
@bot.channel_post_handler(commands=['help', 'hello'])

还要确保bot是通道的管理员。

票数 0
EN

Stack Overflow用户

发布于 2021-12-14 06:27:14

代码语言:javascript
运行
复制
import telebot

from constatnts import API_KEY

bot = telebot.TeleBot(API_KEY, parse_mode=None)


@bot.channel_post_handler(commands=['help', 'hello'])
def send_help_message(msg):
    bot.reply_to(msg, "Hello this is test bot for ml5")
    print(msg)


@bot.message_handler(func=lambda msg: msg.content_type == 'text' )
def send_message(msg):
    bot.reply_to(msg, "Gotcha")

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

https://stackoverflow.com/questions/70107369

复制
相关文章

相似问题

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