[英]telethon forwarding messages to group
我正在創建一個腳本來轉發它完美運行的消息,但我創建了一個圖形界面並將 id 組數據放入 tkinter 條目,然后代碼停止工作我還將 id 放入輸入但它不起作用,the代碼運行但不轉發消息有人知道如何解決它嗎
from telethon import TelegramClient, events
import asyncio
with open('Id1.txt', 'r')as f:
Id_Group1 = f.read()
with open('Id2.txt', 'r')as j:
Id_Group2 = j.read()
print (Id_Group1, Id_Group2)
api_id = '#######'
api_hash = '#######################'
client = TelegramClient('none', api_id, api_hash)
@client.on(events.NewMessage)
async def handler(event):
chat = await event.get_chat()
chat_id = event.chat_id
print('{} {}'.format(chat_id, chat))
if chat_id == Id_Group1:
await client.send_message(Id_Group2, event.raw_text)
client.start()
client.run_until_disconnected()
這不起作用,因為 if 條件下的代碼永遠不會執行。
問題是
chat_id 是 Integer 和 Id_Group1 是一個字符串。
根據 python 和幾乎所有其他編程語言。
“-1001659707082”不等於-1001659707082
這是修改后的代碼..
import asyncio
from telethon import TelegramClient
from telethon.sync import events
Id_Group1 = "-1001659707082"#You can add username and add entity thing instead
Id_Group2 = "thisistest_2"
api_id = 123
api_hash = "12gh3"
print (Id_Group1, Id_Group2)
client = TelegramClient('none', api_id, api_hash)
@client.on(events.NewMessage)
async def handler(event):
chat = await event.get_chat()
chat_id = event.chat_id
if str(chat_id) == Id_Group1:
print('{} {}'.format(chat_id, chat))
await client.send_message(Id_Group2, event.text)
client.start()
client.run_until_disconnected()
還要注意 Id_Group1 和 Id_Group2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.