Telegram 400: Bad Request: group chat was upgraded to a supergroup chat — how to fix it
The group your bot writes to was upgraded to a supergroup, and the supergroup has a new chat id: the old one no longer takes messages. The error carries the new id in parameters.migrate_to_chat_id. Save it in place of the old id and send again, and handle the migrate_to_chat_id service message so the id is updated before the next send fails.
By Livops team, the people who build and run LivopsUpdated
The error, as the Telegram Bot API returns it with error code 400[2]:
Bad Request: group chat was upgraded to a supergroup chat
The response also carries the new chat id, in parameters[1][2]:
{
"ok": false,
"error_code": 400,
"description": "Bad Request: group chat was upgraded to a supergroup chat",
"parameters": { "migrate_to_chat_id": -1001234567890 }
}
Each library wraps it in its own words:
| Library | What you see |
|---|---|
| aiogram 3 | TelegramMigrateToChat: Telegram server says - The group has been migrated to a supergroup with id -1001234567890 from -123456789[6][7] |
| python-telegram-bot | telegram.error.ChatMigrated: Group migrated to supergroup. New chat id: -1001234567890[9][10] |
| grammY | GrammyError: Call to 'sendMessage' failed! (400: Bad Request: group chat was upgraded to a supergroup chat)[13] |
| Telegraf | TelegramError: 400: Bad Request: group chat was upgraded to a supergroup chat[14] |
aiogram and python-telegram-bot raise their own exception for this case and print the new id; grammY and Telegraf keep Telegram’s text and put the id on the error’s parameters. This page explains why the id changed, shows how to read the new one and save it in each library, how to catch the change before a send fails, and what to check when the bot runs on Livops.
What does the error mean?
Telegram has two kinds of group. A basic group is the simple one; a supergroup is the one with the bigger feature set. Upgrading a basic group creates a new supergroup, and Telegram’s API documentation tells apps to do it automatically when an admin tries an action that only supergroups support[3]. For your bot, the result is a different chat with a different id, and all new messages have to be sent to the new supergroup[3].
The old id stays valid as an id, but the group behind it is no longer active. When a bot sends to it, the Bot API server answers Bad Request: group chat was upgraded to a supergroup chat and puts the supergroup’s id into parameters.migrate_to_chat_id[2]. parameters is the optional ResponseParameters object that some errors carry to help you handle them automatically; migrate_to_chat_id is its field for “the group has been migrated to a supergroup with the specified identifier”[1].
So the fix is mechanical: read migrate_to_chat_id, replace the old id with it wherever you stored it, and send again.
How to tell the two ids apart
The Bot API numbers chats so the kind can be read from the id[4]:
- Basic group: the internal id made negative, from
-999999999999to-1. - Supergroup or channel:
-(1000000000000 + id), from-1997852516352to-1000000000001.
So -123456789 is a basic group, and -1001234567890 is a supergroup or channel. The Chat object also says it directly: type is group or supergroup[1]. Ids can need more than 32 bits but at most 52, so store them as a 64-bit integer[1] — BIGINT in SQL.
Fix it in each library
Each example catches the migration, saves the new id, and sends the same message once more. save_chat_id(old, new) stands for your own update, shown in SQL further down.
aiogram 3
aiogram raises TelegramMigrateToChat whenever the response’s parameters contain migrate_to_chat_id, and keeps the id on the exception[6][7]:
from aiogram import Bot
from aiogram.exceptions import TelegramMigrateToChat
async def send(bot: Bot, chat_id: int, text: str) -> int:
try:
await bot.send_message(chat_id, text)
return chat_id
except TelegramMigrateToChat as e:
new_id = e.migrate_to_chat_id
await save_chat_id(chat_id, new_id)
await bot.send_message(new_id, text)
return new_id
python-telegram-bot
python-telegram-bot raises telegram.error.ChatMigrated with the id in new_chat_id[9][10]:
from telegram.error import ChatMigrated
async def send(bot, chat_id: int, text: str) -> int:
try:
await bot.send_message(chat_id, text)
return chat_id
except ChatMigrated as e:
await save_chat_id(chat_id, e.new_chat_id)
await bot.send_message(e.new_chat_id, text)
return e.new_chat_id
grammY
grammY throws a GrammyError that keeps Telegram’s parameters[13]:
import { Bot, GrammyError } from "grammy";
async function send(bot: Bot, chatId: number, text: string): Promise<number> {
try {
await bot.api.sendMessage(chatId, text);
return chatId;
} catch (err) {
const newId = err instanceof GrammyError
? err.parameters.migrate_to_chat_id
: undefined;
if (!newId) throw err;
await saveChatId(chatId, newId);
await bot.api.sendMessage(newId, text);
return newId;
}
}
Telegraf
Telegraf throws a TelegramError whose parameters are Telegram’s ResponseParameters[14]:
const { TelegramError } = require('telegraf');
async function send(telegram, chatId, text) {
try {
await telegram.sendMessage(chatId, text);
return chatId;
} catch (err) {
const newId = err instanceof TelegramError
? err.parameters?.migrate_to_chat_id
: undefined;
if (!newId) throw err;
await saveChatId(chatId, newId);
await telegram.sendMessage(newId, text);
return newId;
}
}
Catch the upgrade before a send fails
When a group is migrated, Telegram posts a service message about it[3], and the Bot API passes it on as a Message with one of two fields[1]:
migrate_to_chat_id— in the old group: “the group has been migrated to a supergroup with the specified identifier”.migrate_from_chat_id— in the new supergroup: “the supergroup has been migrated from a group with the specified identifier”.
All bots receive all service messages, whatever their privacy mode[5], so a handler for them updates the stored id the moment the upgrade happens, not at the next failed send.
aiogram 3. Message has both fields[8]:
from aiogram import F, Router
from aiogram.types import Message
router = Router()
@router.message(F.migrate_to_chat_id)
async def on_migrate(message: Message) -> None:
await save_chat_id(message.chat.id, message.migrate_to_chat_id)
python-telegram-bot. filters.StatusUpdate.MIGRATE matches these messages[12], and Application.migrate_chat_data moves the library’s own chat_data from the old id to the new one; it does not change the chat_id of jobs already scheduled[11]:
from telegram import Update
from telegram.ext import ContextTypes, MessageHandler, filters
async def on_migrate(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
msg = update.effective_message
if msg.migrate_to_chat_id:
await save_chat_id(msg.chat_id, msg.migrate_to_chat_id)
context.application.migrate_chat_data(message=msg)
app.add_handler(MessageHandler(filters.StatusUpdate.MIGRATE, on_migrate))
Keep the error handling from the section above as well: a bot that was offline during the upgrade, or a broadcast that reads ids from the database, still meets the old id.
Update the stored id
If the id lives in a table, change it in one statement. Here in PostgreSQL, with the id as BIGINT:
UPDATE chats
SET chat_id = -1001234567890
WHERE chat_id = -123456789;
Do the same for every other table keyed by that chat — settings, subscriptions, scheduled posts. If the id is hard-coded in the code or set as an environment variable, change it there and redeploy; a send to the old id never starts working again.
On Livops
- Group ids in PostgreSQL. Add PostgreSQL under Databases, and
DATABASE_URLis written into every service in the environment, including services added later. Keep chat ids there asBIGINT, so the update above is one statement and survives deploys. - A fixed group id is a variable. If the bot posts to one group set in a variable such as
GROUP_CHAT_ID, change it under Variables to the new-100…id from the error. New values take effect on the next deploy; restart the service to apply them now. - Logs. Log the old and the new id when you catch the migration; the project’s Logs page and
livops logs <service> -fshow them. - The bot as a service. A Telegram bot is its own service type on Livops,
bot: always running, no public URL needed. The handlers above run in it as they do anywhere else.
A bot costs 19 credits a month (19,000 so’m). One 500 MB database per team is free; see Pricing.
Questions
Why did my group become a supergroup?
Someone upgraded it, often without meaning to. Telegram's apps are told to migrate a basic group to a supergroup automatically when an admin uses a feature only supergroups have. To your bot, the supergroup is a new chat with a new id.
Where do I get the new chat id?
From the error itself. The failed response carries parameters.migrate_to_chat_id, the id of the new supergroup. aiogram puts it on TelegramMigrateToChat.migrate_to_chat_id, python-telegram-bot on ChatMigrated.new_chat_id, and grammY and Telegraf on the error's parameters.
Can I keep sending to the old group id?
No. All new messages have to go to the new supergroup. The old id answers every send with this error, so replace it everywhere you stored it, including variables and scheduled jobs.
How do I tell a supergroup id from a basic group id?
By its range. A basic group id is between -999999999999 and -1. A supergroup or channel id is minus one trillion minus its internal id, so it is below -1000000000000. Chat.type also says group or supergroup.
Will my bot notice the upgrade before a send fails?
Yes, if it listens for it. A service message with migrate_to_chat_id arrives in the old group, and every bot receives service messages whatever its privacy mode. Update the stored id there, and keep catching the error for sends that still use the old id.
Is this the same as chat not found?
No. Chat not found means this bot does not know the id at all. This error means the id is a real group that was upgraded, and the response tells you the new id to use instead.
Sources
- Telegram Bot API — Making requests, ResponseParameters, Message, Chat (core.telegram.org). Checked .
- Telegram Bot API server source — telegram-bot-api/Client.cpp (raw.githubusercontent.com). Checked .
- Telegram — Channels, supergroups, gigagroups and basic groups (Migration) (core.telegram.org). Checked .
- Telegram — Bot API dialog IDs (core.telegram.org). Checked .
- Telegram — Bots FAQ (what messages will my bot get) (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 source — aiogram/types/message.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 .
- python-telegram-bot source — telegram/ext/_application.py (raw.githubusercontent.com). Checked .
- python-telegram-bot source — telegram/ext/filters.py (raw.githubusercontent.com). Checked .
- grammY source — src/core/error.ts (raw.githubusercontent.com). Checked .
- Telegraf source — src/core/network/error.ts (raw.githubusercontent.com). Checked .
Put your project online today
Connect GitHub or drop a folder. No card is asked for.
Deploy your botRelated
- 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.
- Telegram 403: Forbidden: bot can't initiate conversation with a user — how to fix itTelegram bots cannot write first. The user you are sending to has never started a private chat with your bot: you got their id from a group, a shared contact or another system, not from their own /start. Send them your bot's t.me link with a start parameter, save their chat id when the /start arrives, and on this 403 mark the user as unreachable instead of retrying.
- 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 400: Bad Request: not enough rights to send text messages to the chat — how to fix itBad Request: not enough rights to send text messages to the chat means the bot is in the group, but its permissions there do not allow this kind of message: the group's default permissions turn sending off for members, or the bot itself was restricted. Make the bot an administrator, or turn the permission back on; check with getChatMember for the bot's own id. In a channel the bot needs to be an administrator that can post.
- 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 bot hosting in 2026: the options comparedA Telegram bot needs a process that never stops, or a public HTTPS address for a webhook. On Livops it runs from a GitHub push for 19 credits a month (19,000 so'm). Here is how a VPS, Railway, Render, Fly.io and Vercel compare.
- 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).
- grammY bot deploy: polling, webhooks and hostingDeploy a grammY bot as one always-on Node.js process: bot.start() for polling, or webhookCallback() behind an HTTP server, with bot.stop() on SIGTERM. On Livops a repository with grammy in package.json runs as a bot from every push, for 19 credits a month (19,000 so'm).
- Telegraf bot hosting: deploying a Telegraf 4 bot on Node.jsA Telegraf bot is one Node.js process: bot.launch() for polling, or bot.webhookCallback() behind an HTTP server for a webhook, with bot.stop() on SIGTERM. On Livops a repository with telegraf in package.json is run as a bot from every push, for 19 credits a month (19,000 so'm).