6

I am not using bot API. I am using Telegram API to send messages. Messages are being sent easily but the problem occurs after 19 users. On the 20th user, I receive PeerFloodError. Even after, searching a lot, I didn't find any specific limits and using sleep is not working either. Please suggest a way to overcome this problem.

Code

def send_message(root2, client):
    totalcount = 0
    for user in users:
        if totalcount >= len(users):
            root2.destroy()
            break

        if totalcount % 15 == 0 and totalcount != 0:
            print("Waiting for one minute...")
            time.sleep(60)

        if user not in users2 or user not in users3:
            totalcount += 1
            entity = client.get_entity(user)

            client.send_message(entity, message_str)
            time.sleep(8)
Community
  • 1
  • 1
Jaskaran Singh
  • 85
  • 1
  • 1
  • 12

1 Answers1

10

most of the Telegram APIs have strict limits for each of 30-seconds, 30-minutes, 24-hours periods. spread 19(or less API calls in 30 minutes and catch whether it throws an error or not, if it's doing fine after 30minutes: Great! otherwise, do this process for 24 hours.)

note that for a bulk usage of Telegram APIs, you may need to use several accounts in your project.

tashakori
  • 2,331
  • 1
  • 22
  • 29
  • 4
    Thank you so much. It solved my problem. I just increased the sleep time from 8 to 120 (two minutes) to spread 19 requests over 38 minutes and it worked like a charm. – Jaskaran Singh Oct 08 '18 at 16:57
  • at this moment 850s just worked for me. 850s --> 14.16 min (15m). every time the error appears i handle it with: `except PeerFloodError: COOLDOWN += 60` then `time.sleep(COOLDOWN)`. this happened after I waited the whole duration of `telethon.errors.rpcerrorlist.FloodWaitError: A wait of 2322 secont` where it raised after using `InviteToChannelRequest()`. hope it helps.. – Jawad Apr 21 '22 at 04:37
  • **UPDATE**: 850s was enough only for one attempt.. increasing time by +60s seems solved the problem for me. you might need to see issue: [398](https://github.com/LonamiWebs/Telethon/issues/398) – Jawad Apr 21 '22 at 04:54