Forbidden: user is deactivated — the Telegram 403 for a deleted account
The user deleted their Telegram account, or it was deleted for inactivity, and the Bot API refuses every message to it with a 403. It is permanent: the account cannot come back. Catch the error, mark the user inactive or delete the row, and keep the broadcast going.
By Livops team, the people who build and run LivopsUpdated
The full error, as the Telegram Bot API returns it with error code 403[2]:
Forbidden: user is deactivated
Your library wraps it in its own words:
| Library | What you see |
|---|---|
| aiogram 3 | TelegramForbiddenError: Telegram server says - Forbidden: user is deactivated[6][7] |
| python-telegram-bot | telegram.error.Forbidden: Forbidden: user is deactivated[9][10] |
| aiogram 2 | UserDeactivated, a subclass of Unauthorized[8] |
This page explains what the error means, why it is permanent, how it differs from the other 403s a broadcast meets, and how a broadcast loop should catch it, record it and carry on. The code is aiogram 3, with the python-telegram-bot equivalent after it.
What does the error mean?
The account behind that chat id no longer exists. The Bot API server returns this 403 in two places. When Telegram answers a request with its internal INPUT_USER_DEACTIVATED, the server turns that into Forbidden: user is deactivated; and when the server already knows the user of a private chat is deleted, it refuses a send to that chat with the same message before asking Telegram at all[2]. The server takes that state from TDLib’s user types[2], where a deleted user is one about whom nothing but the identifier is known and on whom no active action is possible[3].
So this is not a bug in your code, not a token problem and not a rate limit. The message was not delivered, and no later message to that chat id will be.
Why it is permanent
There are two ways an account ends up deleted, and neither can be reversed:
- The user deleted it. Telegram says deletion removes the account’s messages and contacts and cannot be undone. If the person signs up again, they appear as a new user and do not get their history back[4].
- Telegram deleted it for inactivity. An account that does not come online for a set period, 18 months by default, is deleted with all its data[4].
The second one is why the error shows up in bulk in old user lists: nobody had to do anything, the accounts simply expired. And the first one is why a “comeback” never revives the old row. If the person starts the bot again from a new account, it arrives as a new user.
How is it different from blocked and kicked?
All three are 403s, and all three mean “stop sending here”[2]:
| Description | Where | What happened | Can it change? |
|---|---|---|---|
Forbidden: user is deactivated |
Private chat | The account was deleted | No |
Forbidden: bot was blocked by the user |
Private chat | The user blocked the bot | Yes, if they unblock it |
Forbidden: bot was kicked from the group chat (or supergroup chat, channel chat) |
Group, supergroup, channel | An admin removed the bot | Yes, if someone adds it back |
The blocked case has its own page, Forbidden: bot was blocked by the user, and so does the group case, Forbidden: bot was kicked from the group chat. The practical difference is what you keep. A blocked user may come back, and Telegram tells you when they unblock the bot through a my_chat_member update[1]. A deactivated user will not, and in a private chat my_chat_member arrives only when the user blocks or unblocks the bot[1], so the deletion itself gives you no update. The 403 on send is how you learn about it.
Telegram says the numeric error_code may change in the future[1], so decide on the HTTP status your library already mapped (403) together with the description, not on the number alone.
A broadcast that survives it in aiogram 3
One file, broadcast.py. It reads every active user from a SQLite table, sends the text in BROADCAST_TEXT, waits when Telegram asks it to, and on a 403 records why and moves on. The token comes from BOT_TOKEN.
import asyncio
import logging
import os
import sqlite3
from aiogram import Bot
from aiogram.exceptions import TelegramAPIError, TelegramForbiddenError, TelegramRetryAfter
db = sqlite3.connect(os.path.join(os.environ.get("DATA_DIR", "."), "users.db"))
db.execute(
"CREATE TABLE IF NOT EXISTS users ("
"chat_id INTEGER PRIMARY KEY, "
"status TEXT NOT NULL DEFAULT 'active')" # active, blocked or deleted
)
def set_status(chat_id: int, status: str) -> None:
db.execute("UPDATE users SET status = ? WHERE chat_id = ?", (status, chat_id))
db.commit()
def status_for(error: TelegramForbiddenError) -> str:
# The account is gone for good: it will never be active again.
if "user is deactivated" in error.message:
return "deleted"
return "blocked"
async def send_one(bot: Bot, chat_id: int, text: str) -> None:
while True:
try:
await bot.send_message(chat_id, text)
return
except TelegramRetryAfter as e: # 429: wait as asked, then send again
await asyncio.sleep(e.retry_after)
async def broadcast(bot: Bot, text: str) -> tuple[int, int]:
chat_ids = [row[0] for row in db.execute("SELECT chat_id FROM users WHERE status = 'active'")]
sent = skipped = 0
for chat_id in chat_ids:
try:
await send_one(bot, chat_id, text)
sent += 1
except TelegramForbiddenError as e: # 403: deactivated, blocked
logging.warning("skip %s: %s", chat_id, e.message)
set_status(chat_id, status_for(e))
skipped += 1
except TelegramAPIError as e: # anything else: log it and go on
logging.error("failed %s: %s", chat_id, e.message)
skipped += 1
await asyncio.sleep(0.05)
return sent, skipped
async def main() -> None:
logging.basicConfig(level=logging.INFO)
bot = Bot(os.environ["BOT_TOKEN"])
try:
sent, skipped = await broadcast(bot, os.environ["BROADCAST_TEXT"])
logging.info("sent %s, skipped %s", sent, skipped)
finally:
await bot.session.close()
if __name__ == "__main__":
asyncio.run(main())
What each part does:
- The exception. aiogram turns every HTTP 403 from Telegram into
TelegramForbiddenError, and itsmessageholds Telegram’s description[7][6]. That is howstatus_fortells a deleted account from a block. A response that carriesretry_afterbecomesTelegramRetryAfterinstead, with the wait in seconds[7][6]. - The order of the
exceptblocks.TelegramForbiddenErrorcomes before the generalTelegramAPIError, the base of every Telegram error in aiogram[6]. A 403 marks the user; any other failure is logged and the loop moves on, so one bad chat never stops the rest. - No retry on 403. Only the 429 is retried, after the wait Telegram asks for.
- The pace. Telegram’s FAQ says a bot cannot broadcast more than about 30 messages per second without paid broadcasts, and that going over brings 429 errors[5]. The pause between sends keeps the loop under that; tune it to your list. More in Telegram 429: Too Many Requests.
- Keep or delete. The example keeps the row with
status = 'deleted', so your counts stay honest and the id is never tried again. Since the account cannot return, deleting the row is just as correct:DELETE FROM users WHERE chat_id = ?. A blocked user is different; keep that row, because they may unblock the bot. - Chat ids as 64-bit integers. SQLite’s
INTEGERis enough. In PostgreSQL useBIGINT.
python-telegram-bot v21
The same rules, other names. A 403 becomes telegram.error.Forbidden[10], which was called Unauthorized before version 20.0[9]. python-telegram-bot leaves a Forbidden: description as Telegram sent it[9], so the same text check works:
from telegram.error import Forbidden
try:
await context.bot.send_message(chat_id, text)
except Forbidden as e:
set_status(chat_id, "deleted" if "user is deactivated" in e.message else "blocked")
On Livops
Livops does not filter or retry your sends; the handling above lives in your code. What Livops gives you is the place to run it:
-
The bot as a Bot. A bot runs as the
bottype: always on, no public URL needed. Its exceptions and theskiplines from the loop are on the project’s Logs page and in the terminal withlivops logs <service> -f. -
SQLite while one service uses it. The project has its own disk at
/app/data, and its path is inDATA_DIR, which is why the example builds the SQLite path from it. A file written anywhere else is not kept, and no other service sees this disk. See Files and data. -
PostgreSQL once the sender is a separate service. A scheduled broadcast runs as its own service, so it cannot read the bot’s disk. Keep the users table in PostgreSQL: add it under Databases, and
DATABASE_URLis written into every service in the environment, including ones added later. Store chat ids asBIGINT, and swap thesqlite3calls for your PostgreSQL driver. -
The broadcast as a cron job. A
cronservice runsbroadcast.pyon a schedule read in UTC:0 4 * * *is 09:00 in Tashkent. SetBROADCAST_TEXTas a variable of that service. It must only send and never callgetUpdates, or it conflicts with the bot. The setup is in Cron and workers.{ "kind": "cron", "start": ".venv/bin/python broadcast.py", "schedule": "0 4 * * *" }
A bot, worker or cron job costs 19 credits a month (19,000 so’m); see Pricing.
Questions
Can a deactivated user come back?
No. Telegram says deleting an account cannot be undone. If the same person signs up again, Telegram treats them as a new user, so don't count on the old chat id working again. Your bot sees them again only when they write to it.
Should I retry the message later?
No. The error does not go away with time, so a retry sends the same request and gets the same 403. Mark the user and skip them. Keep retries for 429 Too Many Requests, which asks you to wait and send again.
Why did I get no my_chat_member update when the account was deleted?
In a private chat Telegram sends my_chat_member only when the user blocks or unblocks the bot. Deleting the account is neither, so the first sign is usually the 403 on your next send.
Is this the same as bot was blocked by the user?
Both are 403s and both mean stop sending. Blocked means the person still has an account and may unblock the bot later. Deactivated means the account is gone, so you can delete the row instead of keeping it for a comeback.
Why do so many deactivated users appear in an old user list?
Accounts are also deleted automatically after a period without coming online, 18 months by default. A list collected years ago keeps those chat ids until a send fails and you mark them.
Does this error crash my bot?
Only if the exception escapes your code. Wrap each send of a broadcast in a try block. Without that, the first deleted account stops the loop for every user after it.
Sources
- Telegram Bot API — Making requests, Update, getUpdates (core.telegram.org). Checked .
- Telegram Bot API server source — telegram-bot-api/Client.cpp (raw.githubusercontent.com). Checked .
- TDLib source — td/generate/scheme/td_api.tl (raw.githubusercontent.com). Checked .
- Telegram FAQ — Delete your Telegram account, account self-destruction (telegram.org). Checked .
- Telegram — Bots FAQ, Broadcasting to users (core.telegram.org). Checked .
- aiogram source — aiogram/exceptions.py (raw.githubusercontent.com). Checked .
- aiogram source — aiogram/client/session/base.py (raw.githubusercontent.com). Checked .
- aiogram 2.x source — aiogram/utils/exceptions.py (raw.githubusercontent.com). Checked .
- python-telegram-bot source — telegram/error.py (raw.githubusercontent.com). Checked .
- python-telegram-bot source — telegram/request/_baserequest.py (raw.githubusercontent.com). Checked .
Put your project online today
Connect GitHub or drop a folder. No card is asked for.
Deploy your botRelated
- Telegram 403: Forbidden: bot was blocked by the user — how to handle itThe user blocked the bot, and Telegram refuses every message the bot sends them. Nothing is broken and a retry will not help: catch the 403, mark that user as inactive in your database, skip them in broadcasts, and mark them active again when they write to the bot.
- Telegram 403: Forbidden: bot was kicked from the group chat — how to handle itSomeone removed the bot from that group, supergroup or channel, and Telegram refuses every message it sends there. Nothing is broken and a retry will not help: mark the chat inactive in your database, skip it in broadcasts, and mark it active again when the bot is added back. The my_chat_member update tells you the moment it happens.
- Telegram 429: Too Many Requests, flood control: retry after N — how to fix itTelegram flood control (429 Too Many Requests) is telling your bot to slow down: wait the number of seconds in retry_after, then send the same request again. It comes from sending too fast — more than about one message a second to one chat, 20 a minute to a group, or about 30 a second in a broadcast. Wait and retry in code, and send broadcasts from one queue at a steady pace.
- Telegram 400: Bad Request: chat not found — how to fix itThe bot asked Telegram for a chat it does not know. Either the chat_id is wrong (a typo, a channel id without its -100 prefix, a user's @username, an id cut to 32 bits), or it is right but this bot has never been in that chat: the user never pressed Start, the bot was never added to the group or channel, or the token belongs to a different bot.
- aiogram bot hosting: how to deploy an aiogram 3 botAn aiogram 3 bot needs one process that never stops, the token in an environment variable, state kept outside memory and a clean exit on SIGTERM. On Livops you push a repository with bot.py and requirements.txt, and it runs for 19 credits a month (19,000 so'm), polling or webhook.
- python-telegram-bot hosting: deploying a v22 botA python-telegram-bot bot runs as one Application: run_polling() for polling, run_webhook() with the webhooks extra for a webhook. Both stop cleanly on SIGTERM. On Livops it runs from a push with bot.py and requirements.txt for 19 credits a month (19,000 so'm).