如何解决Telethon:自动回复Telegram停止工作如何解决?
我正在使用以下教程:https://medium.com/@jiayu./automatic-replies-for-telegram-85075f28321
因此,我的代码是:
import time
from telethon import TelegramClient,events
# sample API_ID from https://github.com/telegramdesktop/tdesktop/blob/f98fdeab3fb2ba6f55daf8481595f879729d1b84/Telegram/SourceFiles/config.h#L220
# or use your own
api_id = XXXX
api_hash = 'XXXXXXX'
# fill in your own details here
phone = 'XXXXX'
session_file = '/path/to/session/file' # use your username if unsure
password = 'YOUR_PASSWORD' # if you have two-step verification enabled
# content of the automatic reply
message = "This message is autogenerated.\nApologies,I am unavailable at the moment. Feel free to call me for anything urgent."
count = 1
if __name__ == '__main__':
# Create the client and connect
# use sequential_updates=True to respond to messages one at a time
client = TelegramClient(session_file,api_id,api_hash,sequential_updates=True)
@client.on(events.NewMessage(incoming=True))
async def handle_new_message(event):
if event.is_private: # only auto-reply to private chats
from_ = await event.client.get_entity(event.from_id) # this lookup will be cached by telethon
if not from_.bot: # don't auto-reply to bots
print(count,time.asctime(),'-',event.message) # optionally log time and message
# print( '-',time.asctime()) # optionally log time and message
count += 1 # incrementing the count
time.sleep(1) # pause for 1 second to rate-limit automatic replies
await event.respond(message)
print(time.asctime(),'Auto-replying...')
client.start(phone,password)
client.run_until_disconnected()
print(time.asctime(),'Stopped!')
我第一次运行该代码时,它运行良好。然后我停止了它,更改了消息,它不再起作用了。它以消息“自动答复...”启动,但不答复Telegram上的消息。重新启动计算机或删除会话文件无济于事。
与电报阻止连接有关吗?
编辑:有时它可以正常工作。有时它根本不起作用:(
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。