当达到列表中的一定数量的行(计数行)时,Telethon定期重复该操作
请帮助我执行取决于行数的操作。因此,该程序的任务是跟踪该组中有多少消息,然后当这些消息的值达到一定数字时,执行操作以将消息发送给同一组。
from telethon import TelegramClient, sync
from telethon.events import NewMessage
api_id = '____'
api_hash = '______'
client = TelegramClient('session_name', api_id, api_hash)
@client.on(event=NewMessage(chats=('https://t.me/some_group')))
async def normal_handler(event):
value = event.message.to_dict()['message']
lines = 0
for line in value:
lines += 1
print(lines)
if lines % 2: #the task is to send messages every 2 income messages
await client.send_message('https://t.me/some_group', message='something')
client.start()
client.run_until_disconnected()
当前,该程序分别向我显示每个消息,并计算此特定消息中字符的数量,然后继续进行下一个消息。
我感谢您的耐心:)
非常感谢您
Please help me with the execution of an action that depends on the number of lines. So, the task of the program is to track how many messages were in the group, and then when the value of these messages reaches a certain number, perform an action to send a message to the same group.
from telethon import TelegramClient, sync
from telethon.events import NewMessage
api_id = '____'
api_hash = '______'
client = TelegramClient('session_name', api_id, api_hash)
@client.on(event=NewMessage(chats=('https://t.me/some_group')))
async def normal_handler(event):
value = event.message.to_dict()['message']
lines = 0
for line in value:
lines += 1
print(lines)
if lines % 2: #the task is to send messages every 2 income messages
await client.send_message('https://t.me/some_group', message='something')
client.start()
client.run_until_disconnected()
Currently, the program shows me each message separately and counts the number of characters in this particular message, and then proceeds to the next message.
I am grateful for your patience :)
Thank you very much in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)