Telephon将消息转发到组



我正在创建一个转发消息的脚本,它运行得很好,但我创建了一个图形界面,并将id组数据放在tkinter条目中,然后代码停止工作,我也将id放在输入中,但它不起作用,代码运行但不转发消息有人知道如何解决吗

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是和IntegerId_Group1是一个字符串。

根据python和几乎所有其他编程语言。

&quot-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

最新更新