0

因此,我必须将传入的频道帖子转发到我的私人聊天室以进行测试。现在,它有效,但仅适用于 texts。如果频道帖子是媒体,则不会转发消息。

那是转发帖子的代码:

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

4

1 回答 1

0

好吧,我想出了如何让它工作。使用 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

于 2020-09-11T12:52:31.160 回答