Python Telebot - 转发不适用于媒体

Python Telebot - Forwarding is not working for media

因此,我必须将传入频道 post 转发到我的 私人聊天 以进行测试。现在,它可以工作,但 仅适用于文本 。如果频道 post 是 媒体 ,它 不会 转发消息。

这是转发 post 的代码:

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

相同的参数