电视将消息转发给小组

发布于 2025-01-19 12:37:42 字数 749 浏览 1 评论 0原文

我正在创建一个脚本来转发消息完美奏效,但是我创建了一个图形界面并将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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

壹場煙雨 2025-01-26 12:37:42

这是行不通的,因为 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

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..

    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()

Also watch the Id_Group1 and Id_Group2

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文