我正在使用 pyrogram 来循环我们在保存消息中拥有的所有消息,但是当我遍历它时。它不会破坏它正在运行,直到消息结束并且我不想要它我已经放了 break statments 但不工作然后我试过了为了检查它为什么不工作,我评论了 pyrogram 的 send_message 函数然后它工作但如果我使用该函数它不工作。这是代码:
from apscheduler.schedulers.asyncio import AsyncIOScheduler
import time
from pyrogram import Client, filters
from pyrogram.errors import PeerIdInvalid
app = Client("account")
sent = []
dialogs = []
async def job():
global dialogs
print("started")
print("getting chats")
if not dialogs:
dialogs = await app.get_dialogs()
print("got it")
async for messag in app.iter_history("me"):
try:
if messag in sent:
# print(message.text)
continue
else:
for dialog in dialogs:
if (dialog.chat.type == "supergroup") or (dialog.chat.type == "group"):
try:
print(str(dialog.chat.username) + "-" + str(dialog.chat.id) +
" : " + str(dialog.chat.type))
await app.send_message(dialog.chat.id, messag.text)
sent.append(messag)
except PeerIdInvalid:
try:
await app.send_message(dialog.chat.username, messag.text)
sent.append(messag)
except Exception as error:
print(error)
continue
except KeyboardInterrupt:
break
print("breaking")
break
break
except Exception as error:
if "NoneType" in str(error):
print("nontype : " + str(error))
print(error)
print("out of the loop")
scheduler = AsyncIOScheduler()
scheduler.add_job(job, "interval", minutes=1)
scheduler.start()
app.run()