nblockchain / TgSharp

Telegram client library implemented in C#
32 stars 12 forks source link

Sendmessage error:Flood prevention #33

Open tz182736 opened 4 years ago

tz182736 commented 4 years ago

"Flood prevention. Telegram now requires your program to do requests again only after 3600 seconds have passed (TimeToWait property), so if now it's 11/10/2020 3:59:32 AM, wait until 11/10/2020 4:59:32 AM If you think the culprit of this problem may lie in TgSharp's implementation, open a Github issue please."

this error cause on first debug right after authorize and try to send text message

////  CLIENT CONNECT
    var store = new FileSessionStore();
    client = new TelegramClient(apiId, apiHash, dcIpVersion: DataCenterIPVersion.OnlyIPv4, store:null, sessionUserId: "_session");
    await client.ConnectAsync();

/////  CLIENT REQUEST
    userHash = await client.SendCodeRequestAsync(txtUserNumber.Text);

////  CLIENT AUTH
    var user = await client.MakeAuthAsync(txtUserNumber.Text, userHash, txtRequestCode.Text);

//// CLIENT SEND MESSAGE
    //get available contacts
    var result = await client.GetContactsAsync();

    //find recipient in contacts
    var user = result.Users
        .Where(x => x.GetType() == typeof(TLUser))
        .Cast<TLUser>()
        .FirstOrDefault(x => x.Phone == txtNumberToSend.Text);

    await client.SendMessageAsync(new TLInputPeerUser() { UserId = user.Id }, txtMessage.Text);