FLOOD_WAIT_X error occurs in Telegram bot only in production environment

I’m working with a Telegram bot using the WTelegramClient library and encountering a strange problem. The bot functions perfectly when I run it in debug mode via Visual Studio, but it fails to work when I publish it as a console application.

When in debug mode, everything runs smoothly. I can input the api_id, api_hash, phone_number, and verification_code without any issue. The login process goes through successfully.

However, when I publish the app and execute the file, I receive a FLOOD_WAIT_X error right after entering the phone number. This occurs precisely when Telegram is supposed to send the verification code.

Here is the part of my authentication code:

static async Task Main(string[] args)
{
    var telegramClient = new WTelegram.Client();
    
    await telegramClient.LoginUserIfNeeded();
    
    var user = await telegramClient.GetMe();
    Console.WriteLine($"Logged in as {user.first_name}");
}

static string ConfigProvider(string setting)
{
    switch (setting)
    {
        case "api_id": return ReadInput("Enter API ID: ");
        case "api_hash": return ReadInput("Enter API Hash: ");
        case "phone_number": return ReadInput("Enter phone: ");
        case "verification_code": return ReadInput("Enter code: ");
        default: return null;
    }
}

I’ve attempted several approaches such as introducing delays between requests, utilizing environment variables for settings, deploying to various hosting services, and adjusting publish configurations. Yet, the error consistently emerges at the same stage in production mode only.

yea i think ur right, could be rate limits messin with ya. try saving the session state, that way u won’t need to log in all the time. that might help with those flood_wait errors!

This happens because your session files are stored in different places when debugging vs. production. Visual Studio puts them somewhere else than your published app, so Telegram thinks you’re doing a fresh login every time with the same phone number - that’s why you get FLOOD_WAIT_X errors.

I had the same issue with my bot. Fix it by updating your ConfigProvider method to handle session file paths properly. Add a case for “session_pathname” that returns the same file path in both environments. This way WTelegramClient can reuse existing sessions instead of trying to authenticate fresh each time. Just make sure your production environment can actually write to wherever you put the session file.

Sounds like your production environment handles network requests differently than Visual Studio’s debug mode. VS gives your app different network properties and might route through different proxy settings or adapters. I hit the same thing deploying a Telegram bot to my VPS - the production server was hammering requests way harder than my local setup. Fixed it by adding exponential backoff for auth requests and making sure I wasn’t running multiple instances at once. Check if your host throttles requests or if you’ve got duplicate processes running. Also worth checking if Telegram flagged your server’s IP - they treat server IPs way stricter than home connections.