簡體   English   中英

如何使用Telethon轉發每個頻道的更新

[英]How to forward every channels updates using Telethon

我想將所有更新從渠道轉發到我的機器人。 ForwardMessagesRequest是否可能? 我嘗試使用此Telethon示例構建個人代碼:

https://github.com/LonamiWebs/Telethon/wiki/Forwarding-messages

但是我做不到。 而且我不知道是否有可能在回調函數中使用那部分代碼。 有人可以幫我嗎? 謝謝

好吧,我真的很困惑,讓我們回去。

在這段代碼中,我只是嘗試從用戶聊天中檢索最后一條消息,並將其轉發給我的機器人:

def callback(update):

source_chat_id = "here i put the user id"
source_hash = "here i put his access_hash"

source_chat = InputPeerUser(source_chat_id, source_hash)
total_count, messages, senders = client.get_message_history(
                source_chat, limit=10)

for msg in reversed(messages):
    print ("msg:", msg.id, msg)

msg = messages[0]    
print ("msg id:", msg.id)

dest_chat = "here i tried to put the number of my bot ID"   

result = client.invoke(ForwardMessagesRequest(from_peer=source_chat, id=[msg.id], random_id=[generate_random_long()], to_peer=dest_chat))


client.add_update_handler(callback)

打印是正確的,但是我的機器人聊天程序沒有收到任何信息。 我知道會有很多錯誤,所以請耐心和抱歉。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM