gpt4 book ai didi

python - 如何进入下一个循环?

转载 作者:太空狗 更新时间:2023-10-30 02:53:19 24 4
gpt4 key购买 nike

如果有新成员加入,此代码会向 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()

“继续”功能在这种情况下不起作用。

这里的功能描述:https://docs.pyrogram.ml/resources/UpdateHandling

最佳答案

只需添加 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()

关于python - 如何进入下一个循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50006973/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com