Python Telebot-转发不适用于媒体

问题描述

因此,我必须将进入频道的帖子转发到我的私人聊天,以进行测试。现在,它可以使用,但仅适用于文本。如果频道信息是媒体,则转发邮件

这是转发帖子的代码

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相同的参数

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...