问题描述
因此,我必须将进入频道的帖子转发到我的私人聊天,以进行测试。现在,它可以使用,但仅适用于文本。如果频道信息是媒体,则不转发邮件。
这是转发帖子的代码:
bot.forward_message(myId,'@ ' + username,msg.message_id)
# Where: myId is my telegram chat ID; '@' + username is the channel (done like this because
# there will be multiple channels); msg.message_id is the ID of the message it has to forward
我正在使用库pyTelegramBotAPI(模块的名称为 telebot )
解决方法
好的,我弄清楚了如何使其工作。使用pyTelegramBotAPI,只需将content_types参数放入装饰器中即可:
@bot.channel_post_handler(content_types = ['text','photo','video','gif','sticker'])
def channel_post_handler(msg):
# Your code here
可以在@bot.message_handler
中进行相同的操作,因为您可以将其传递给@bot.channel_post_handler
相同的参数