电视将消息转发给小组
我正在创建一个脚本来转发消息完美奏效,但是我创建了一个图形界面并将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()
I'm creating a script to forward messages it worked perfectly, but I created a graphical interface and put the id group data in tkinter entries, and then the code stopped working I also put the ids in inputs and it doesn't work,
the code runs but does not forward the msg would anyone know how to solve it
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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是行不通的,因为 if 条件下的代码永远不会执行。
问题是
chat_id 是 Integer 和
Id_Group1 是一个字符串。
根据Python和几乎所有其他编程语言。
“-1001659707082”不等于-1001659707082
这是修改后的代码..
还要注意 Id_Group1 和 Id_Group2
This is not working because your code in if condition will never execute.
The problem is
chat_id is and Integer and
Id_Group1 is a String.
according to python and almost all other programming language.
"-1001659707082" is not equal to -1001659707082
Here is the modified codes..
Also watch the Id_Group1 and Id_Group2