避免在Python中泛滥
我是 Pyrogram 的新手,我尝试制作订阅机器人
,我想在任何满足我的过滤器的消息时立即发送消息,但每次我连续发送超过 3 条消息时,我都会收到 FloodWait 错误。捕获那个异常是没有问题的,但是它总是变大
15 -> 60->第333章-> 417秒
我该如何避免?每条消息后睡几秒钟并没有帮助。我在文档中没有找到任何有关确切估计等待时间的信息
for user in subs_arr:
try:
app.send_message(user, msg)
time.sleep(10)
except pyrogram.errors.exceptions.flood_420.FloodWait as wait_err:
wait_err = str(wait_err)
time.sleep(wait_err.x)
I am new to Pyrogram and I try to make subsctiption bot
I want to send messages as soon as any satisfy my filters, but every time I send more than 3 messages in a row I get FloodWait error. There is no problem in catching that exception, but it is always getting bigger
15 -> 60 -> 333 -> 417 seconds
How can I avoid it? Sleeping for some seconds after every message doesn't help. And I didn't find anything about exact estimated waiting time in docs
for user in subs_arr:
try:
app.send_message(user, msg)
time.sleep(10)
except pyrogram.errors.exceptions.flood_420.FloodWait as wait_err:
wait_err = str(wait_err)
time.sleep(wait_err.x)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过一番研究,我发现无法避免洪水处理:D
,但我对时间的理解完全错误。我在该机器人的机器上使用了pyrargram,我不需要它的异步组件
然而,机器人需要异步睡眠,我在这种方式上重新加工时遇到了问题。最后,我想出了该解决方案(现在睡觉通常是< = 60秒)
希望它会帮助某人,甚至有人会建议我更好的方法
After some research I found that there is no way to avoid FloodWait :D
But I had totally wrong understanding of time.sleep. I used Pyrogram for that bot, bot I didn't need async component of that
Nevertheless bot requires asynchronous sleep and I had problems with reworking it this way. Finally I came up with that solution (now sleep usually is <=60 second)
Hope it'll help somebody or even somebody will advice me better way of doing this