Introducing Livops 2.0! Promo codeCEOgives you 8,000 so‘m on your balance.What’s new

Bad Request: message is not modified — Telegram bot error and how to fix it

Bad Request: message is not modified means your bot asked Telegram to edit a message into exactly what it already shows: the same text, caption and inline keyboard. It usually comes from a user pressing the same button twice or a refresh button with nothing new. Skip the edit when nothing changed, or catch this exact error and ignore it.

By Livops team, the people who build and run LivopsUpdated

The error, as the Telegram Bot API returns it when an edit would change nothing:

{"ok":false,"error_code":400,"description":"Bad Request: message is not modified: specified new message content and reply markup are exactly the same as a current content and reply markup of the message"}

In short: your bot called editMessageText, editMessageCaption or editMessageReplyMarkup with exactly the text, caption and inline keyboard the message already shows, so Telegram refused the edit. It is harmless and usually comes from a user pressing the same button twice. Skip the edit when nothing changed, or catch this one error and ignore it; either way, still answer the callback query.

Each library wraps it in its own words:

Library What you see
aiogram 3 TelegramBadRequest: Telegram server says - Bad Request: message is not modified: ...[4][5]
python-telegram-bot telegram.error.BadRequest: Message is not modified: ...[7][8]
grammY GrammyError: Call to 'editMessageText' failed! (400: Bad Request: message is not modified: ...)[11]
Telegraf TelegramError: 400: Bad Request: message is not modified: ...[14]

This page explains what the error means, lists where it comes from, and shows the two fixes — skip an edit that changes nothing, or catch this one error and ignore it — in aiogram, python-telegram-bot, grammY and Telegraf. It ends with what to check when the error stops the whole bot, and how it looks on Livops.

What does the error mean?

editMessageText, editMessageCaption and editMessageReplyMarkup change a message that is already in the chat instead of sending a new one, which Telegram says is most useful for messages with inline keyboards[1]. Telegram’s own advice is to edit the keyboard when a user toggles a setting or moves to a new page, rather than send a new message[2].

The error means the edit you asked for would leave the message exactly as it is. Telegram’s servers report this as MESSAGE_NOT_MODIFIED, and the Bot API server turns it into the text above with code 400 and the prefix Bad Request[3]. The message is not damaged and nothing was sent; the request was simply not needed.

Match the error by its description, not by its code alone: a failed request has ok set to false and the reason in description, while the contents of error_code are subject to change[1]. Many other mistakes are a 400 too.

Where it comes from, most common first

1. The user presses the same button twice

The first press edits the message into the new state. A second press of the same button — a double tap, or a press while the first edit is still on its way — asks for that same state again. The text and keyboard you build are identical to what is shown, and the edit fails.

2. A button that leads to where the user already is

  • a “◀ Back” arrow on page 1, or “Next ▶” on the last page, that rebuilds the same page;
  • a Refresh button when the data has not changed since the last refresh;
  • a settings toggle or a choice in a list that is already selected.

3. The same content written in different markup

With parse_mode, the Bot API server turns HTML, Markdown or MarkdownV2 into plain text plus formatting entities before the edit goes to Telegram[3]. So <b>Total: 5</b> with HTML and *Total: 5* with MarkdownV2 both describe the text Total: 5 in bold: if only the markup language changes, the message itself may not, and the edit can be refused as not modified.

4. Only the caption or only the keyboard

editMessageCaption edits a caption, and editMessageReplyMarkup edits only the keyboard[1]. Sending the caption or the keyboard the message already has gives the same error: the message’s content and keyboard would both stay as they are.

How to fix it

Compare before you edit

The cleanest fix is not to send the edit. Keep the state the message shows — the page number, the selected option, a version of the data — and skip the edit when the new state is the same. Answer the callback query either way, so the button stops loading.

# aiogram 3: the buttons carry the page they lead to and the page shown now
@router.callback_query(F.data.startswith("page:"))
async def on_page(callback: CallbackQuery):
    _, target, current = callback.data.split(":")
    await callback.answer()
    if target == current:
        return  # nothing would change
    await callback.message.edit_text(render_page(int(target)), reply_markup=page_kb(int(target)))

Comparing text is harder than it looks. message.text holds plain text; the formatting is in its entities. To compare with text you send as HTML, rebuild the HTML from the message first: aiogram’s Message.html_text[6], python-telegram-bot’s Message.text_html[9]. The rebuilt HTML is not always written the way you wrote yours, so keep the except below as a safety net.

Catch this exact error and ignore it

When an identical edit is harmless — and it usually is — catch the bad request, check its text, and raise everything else.

aiogram 3. Telegram’s 400 is TelegramBadRequest, and its message is Telegram’s description[4][5]:

from aiogram.exceptions import TelegramBadRequest

try:
    await callback.message.edit_text(text, reply_markup=kb)
except TelegramBadRequest as e:
    if "message is not modified" not in e.message:
        raise

python-telegram-bot. Telegram’s 400 is BadRequest[7][8]. The library removes the Bad Request: prefix and capitalizes the rest, so the text starts with Message is not modified[7]; compare in lower case:

from telegram.error import BadRequest

try:
    await query.edit_message_text(text, reply_markup=kb)
except BadRequest as e:
    if "message is not modified" not in e.message.lower():
        raise

query.edit_message_text is the shortcut on the CallbackQuery[10].

grammY. API errors are GrammyError, with Telegram’s description and error_code on it[11]:

import { GrammyError } from "grammy";

try {
  await ctx.editMessageText(text, { reply_markup: kb });
} catch (e) {
  if (!(e instanceof GrammyError && e.description.includes("message is not modified"))) throw e;
}

ctx.editMessageText is grammY’s shortcut for the message the update is about[13].

Telegraf. API errors are TelegramError, with code and description getters[14]:

import { TelegramError } from "telegraf";

try {
  await ctx.editMessageText(text, { reply_markup: kb });
} catch (e) {
  if (!(e instanceof TelegramError && e.description.includes("message is not modified"))) throw e;
}

ctx.editMessageText is Telegraf’s shortcut too[16].

Write the check once — a small safe_edit helper, or the library’s error handler — rather than around every edit.

When it stops the whole bot

The error itself is harmless; an uncaught one is not always.

  • grammY. Without bot.catch, the default error handler logs the error, prints No error handler was set!, and stops the bot if it runs with bot.start()[12]. Install a handler: bot.catch((err) => console.error(err.error)), and skip this error there if you like.
  • Telegraf. The default error handler sets the exit code to 1, logs the update and rethrows the error[15]. Replace it with bot.catch((err, ctx) => { ... })[15].
  • aiogram and python-telegram-bot keep running. aiogram’s polling logs Cause exception while process update ... and moves on[17]; python-telegram-bot with no error handler logs No error handlers are registered, logging exception.[18] Either way, the rest of that handler — everything after the failed edit — does not run.

On Livops

This error happens while the bot runs, when a user presses a button; a deploy does not press your buttons, so it can be green while a button misbehaves.

  • Logs. The error line is on the project’s Logs page, and livops logs <service> -f follows it from the terminal; see CLI. Over MCP, get_logs returns up to 5000 lines.
  • If it stops the bot right after a deploy. If an uncaught error stops the bot right after it starts, the deploy fails as start_failed, with the bot’s last words on the Logs page. A bot’s old version is stopped before the new one starts, so the bot stays down until a deploy succeeds. See The app did not start.
  • Ship the fix with a push. Push the try/except or the state check, and the new version replaces the old one.

A bot costs 19 credits a month (19,000 so’m); see Pricing.

Questions

What does message is not modified mean in a Telegram bot?

The bot called editMessageText, editMessageCaption or editMessageReplyMarkup, and the new text and keyboard are exactly what the message already shows. Telegram refuses an edit that changes nothing and answers with 400 Bad Request. Nothing is broken; the edit was simply not needed.

Is it safe to ignore message is not modified?

Yes, as long as you ignore only this exact error. The message already looks the way you wanted. Catch the library's bad request error, check that its text contains message is not modified, and raise everything else, so a real problem such as a message that cannot be edited still shows up in the log.

Why does it happen when a user presses the same button twice?

The first press already edited the message into the new state. The second press asks for the same state again, so the edit changes nothing. Pagination arrows on the first or last page, refresh buttons and settings toggles that land on the value already shown are the usual places.

My code sends different text, so why does Telegram say it is the same?

With parse_mode set, the markup is turned into plain text plus formatting entities before the edit reaches Telegram. Two strings written in different markup, for example HTML and MarkdownV2, can describe the same text and formatting, and then the edit may not change the message.

How can I avoid the error without try and except?

Compare before you edit. Keep the state the message shows, such as the page number or the selected option, in the callback data or in your storage, and skip the edit when the new state is the same. Still answer the callback query, so the button stops loading.

Can this error crash my bot?

It can if nothing catches it. grammY without bot.catch logs the error and stops the bot when it runs with bot.start, and Telegraf's default error handler rethrows it. Catch it where you edit, or install an error handler that ignores it.

Do I still have to answer the callback query when I skip the edit?

Yes. After a user presses a callback button, Telegram clients show a progress bar until the bot calls answerCallbackQuery, and Telegram says to call it even when no notification is needed. Answer it first, then skip or make the edit.

Sources

  1. Telegram Bot API — Making requests, Formatting options, Updating messages, editMessageText, editMessageCaption, editMessageReplyMarkup (core.telegram.org). Checked .
  2. Telegram — Bot features (Inline keyboards) (core.telegram.org). Checked .
  3. Telegram Bot API server source — telegram-bot-api/Client.cpp (raw.githubusercontent.com). Checked .
  4. aiogram source — aiogram/exceptions.py (raw.githubusercontent.com). Checked .
  5. aiogram source — aiogram/client/session/base.py (raw.githubusercontent.com). Checked .
  6. aiogram source — aiogram/types/message.py (raw.githubusercontent.com). Checked .
  7. python-telegram-bot source — telegram/error.py (raw.githubusercontent.com). Checked .
  8. python-telegram-bot source — telegram/request/_baserequest.py (raw.githubusercontent.com). Checked .
  9. python-telegram-bot source — telegram/_message.py (raw.githubusercontent.com). Checked .
  10. python-telegram-bot source — telegram/_callbackquery.py (raw.githubusercontent.com). Checked .
  11. grammY source — src/core/error.ts (raw.githubusercontent.com). Checked .
  12. grammY source — src/bot.ts (raw.githubusercontent.com). Checked .
  13. grammY source — src/context.ts (raw.githubusercontent.com). Checked .
  14. Telegraf source — src/core/network/error.ts (raw.githubusercontent.com). Checked .
  15. Telegraf source — src/telegraf.ts (raw.githubusercontent.com). Checked .
  16. Telegraf source — src/context.ts (raw.githubusercontent.com). Checked .
  17. aiogram source — aiogram/dispatcher/dispatcher.py (raw.githubusercontent.com). Checked .
  18. python-telegram-bot source — telegram/ext/_application.py (raw.githubusercontent.com). Checked .

Put your project online today

Connect GitHub or drop a folder. No card is asked for.

Deploy your bot

Got a question? — @livops_uz