如果新成员加入,此代码会向Telegram Supergroup发送消息。发送邮件时发生错误,我想更改我的帐户以继续。可以转到下一个"项目"。 收到错误后,如何在循环中转到下一个帐户?
from pyrogram import Client, Filters
list_account = ['001', '002']
for item in list_account:
app = Client(item)
@app.on_message(Filters.chat("public_link_chat") & Filters.new_chat_members)
def welcome(client, message):
try:
client.send_message(
message.chat.id, 'Test',
reply_to_message_id=message.message_id,
disable_web_page_preview=True
)
except Exception as e:
print(e)
# How do I go to the next account in a loop when I receive an error?
app.start()
app.join_chat("public_link_chat")
app.idle()
功能"继续"在这种情况下不起作用。
答案 0 :(得分:4)
只需添加app.is_idle = False
:
from pyrogram import Client, Filters
list_account = ['001', '002']
for item in list_account:
app = Client(item)
@app.on_message(Filters.chat("public_link_chat") & Filters.new_chat_members)
def welcome(client, message):
try:
client.send_message(
message.chat.id, 'Test',
reply_to_message_id=message.message_id,
disable_web_page_preview=True
)
except Exception as e:
print(e)
# How do I go to the next account in a loop when I receive an error?
app.is_idle = False
app.start()
app.join_chat("public_link_chat")
app.idle()
你一定要在热门图源代码中查看these lines空闲逻辑:
while self.is_idle:
time.sleep(1)
如果你想要一个无限循环,check out itertools.cycle
,它可以像:
for item in itertools.cycle(list_account):
do_something()