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

Bad Request: message to be replied not found — Telegram bot error and how to fix it

Bad Request: message to be replied not found means Telegram could not find the message your bot tried to reply to, so nothing was sent: it was deleted, its message_id belongs to another chat or forum topic, or the bot cannot see that chat. Pass reply_parameters with allow_sending_without_reply set to true to send the message anyway, take the message_id from the same chat, and catch the error where the reply is optional.

By Livops team, the people who build and run LivopsUpdated

The error, as the Telegram Bot API returns it[3]:

{"ok":false,"error_code":400,"description":"Bad Request: message to be replied not found"}

Each library wraps it in its own words:

Library What you see
aiogram 3 TelegramBadRequest: Telegram server says - Bad Request: message to be replied not found[7][8]
python-telegram-bot telegram.error.BadRequest: Message to be replied not found[12][13]
grammY GrammyError: Call to 'sendMessage' failed! (400: Bad Request: message to be replied not found)[18]
Telegraf TelegramError: 400: Bad Request: message to be replied not found[21]

Older versions of the Bot API server worded the same error differently, and old answers and issues still quote them:

Description In the server’s source
Bad Request: reply message not found When it was first published, in November 2020[6]
Bad Request: replied message not found Later versions, until October 2023[4]
Bad Request: message to reply not found October 2023 to May 2024[4][5]
Bad Request: message to be replied not found Since May 2024[5]

This page explains when the Bot API server gives this error, the causes from the most common, and the fixes — allow_sending_without_reply, the right chat and topic, and catching the error — in aiogram, python-telegram-bot, grammY and Telegraf. It ends with how to find the failing send on Livops.

What does the error mean?

Every send method can send its message as a reply: you pass reply_parameters, whose message_id is the message to reply to in the current chat, or in the chat named by its own chat_id[1]. Before it sends anything, the Bot API server looks that message up[3]:

  • If the message would be in a supergroup or channel the bot is not a member of, the bot cannot see its messages, and the server answers message to be replied not found straight away[3].
  • Otherwise it asks for the message. If there is none and allow_sending_without_reply is not set, it answers with this error; if it is set, the message goes out as a normal message, not a reply[3].
  • allow_sending_without_reply is always false for replies in another chat or forum topic[1]. There, a missing message is an error whatever you pass.

So the whole message failed, not just the reply. It is a 400, and Telegram says the numeric error_code may change in the future[1], so match on the description.

reply_to_message_id is now reply_parameters

Bot API 7.0, on December 29, 2023, replaced the reply_to_message_id and allow_sending_without_reply parameters of the send methods with one field, reply_parameters[2]. The Bot API server still reads the two old parameters when reply_parameters is absent; when reply_parameters is present, it reads only that[3]. A request that sets reply_parameters and a top-level allow_sending_without_reply therefore loses the flag. The documentation now lists only reply_parameters[1].

Causes, most common first

1. The message was deleted before the reply

The user deleted their message, an administrator or an anti-spam bot removed it, or your own code did — a bot that deletes a command to keep the group clean and then replies to it without the flag meets this error every time. A slow handler, such as one that waits for a payment check or a language model, gives a deletion more time to happen. The server finds no message[3].

Fix: send with allow_sending_without_reply: true (below), or reply first and delete afterwards.

2. The message_id is from another chat

A message_id is unique only inside its chat[1]. Message 42 in a private chat has nothing to do with message 42 in your admin group. The usual mistake: the bot forwards a user’s question to an admin group and replies there with the id of the user’s original message. The server looks for that id in the admin group: if there is no such message there, it gives this error[3].

Fix: reply in the chat the message is in. To reply across chats on purpose, put the original chat in reply_parameters.chat_id; Bot API 7.0 added replies to messages in other chats and forum topics[2]. Then allow_sending_without_reply is always false[1], and in a supergroup or channel the bot must be a member to see the message[3].

3. The message is in another forum topic

In a forum supergroup, the target topic is the send method’s message_thread_id[1]. Sending into topic A as a reply to a message in topic B is a reply in another forum topic[2], so allow_sending_without_reply is always false[1] and a deleted message in topic B fails even with the flag. Fix: send into the topic the message is in. The reply shortcuts do that for you: aiogram’s message.reply sets the thread when the message is a topic message[11], and so do grammY’s ctx.reply[19] and Telegraf’s ctx.reply[22].

4. The bot is not in the chat the message is in

When reply_parameters.chat_id names a supergroup or channel the bot is not a member of, the server answers this error before it looks for the message, whatever allow_sending_without_reply says[3]. Fix: add the bot to that chat, or reply without chat_id. Sending to such a chat fails differently; see bot is not a member of the channel chat.

How to fix it

Send anyway: allow_sending_without_reply

With the raw Bot API, reply_parameters is a JSON object[1][3]:

curl -s "https://api.telegram.org/bot$BOT_TOKEN/sendMessage" \
  --data-urlencode "chat_id=$CHAT_ID" \
  --data-urlencode "text=Done" \
  --data-urlencode 'reply_parameters={"message_id":42,"allow_sending_without_reply":true}'

aiogram 3. ReplyParameters.allow_sending_without_reply takes the bot’s default when you leave it out[9], and DefaultBotProperties has an allow_sending_without_reply default[10]. message.reply builds its ReplyParameters with that default[11], so one line covers every reply:

from aiogram import Bot
from aiogram.client.default import DefaultBotProperties
from aiogram.types import ReplyParameters

bot = Bot(token=TOKEN, default=DefaultBotProperties(allow_sending_without_reply=True))

# or for one message
await message.answer(
    "Done",
    reply_parameters=ReplyParameters(message_id=message.message_id, allow_sending_without_reply=True),
)

python-telegram-bot 21 and later. ReplyParameters takes message_id, chat_id and allow_sending_without_reply[14]. send_message still accepts reply_to_message_id and allow_sending_without_reply as keyword-only convenience arguments, but not together with reply_parameters[15]. Defaults(allow_sending_without_reply=True) is used for ReplyParameters.allow_sending_without_reply[16], and the application builder takes it with .defaults()[17]:

from telegram import ReplyParameters
from telegram.ext import ApplicationBuilder, Defaults

app = ApplicationBuilder().token(TOKEN).defaults(Defaults(allow_sending_without_reply=True)).build()

# or for one message
await context.bot.send_message(
    chat_id=update.effective_chat.id,
    text="Done",
    reply_parameters=ReplyParameters(
        message_id=update.effective_message.message_id,
        allow_sending_without_reply=True,
    ),
)

grammY. ctx.reply passes your options to sendMessage[19], and its types include reply_parameters with allow_sending_without_reply[20]:

bot.on("message", async (ctx) => {
  await ctx.reply("Done", {
    reply_parameters: { message_id: ctx.msg.message_id, allow_sending_without_reply: true },
  });
});

Telegraf. ctx.reply is sendMessage to the current chat[22]. Telegraf 4.16.3 depends on @telegraf/types 7.1[23], whose ReplyParameters has message_id and allow_sending_without_reply[24]:

bot.on("message", async (ctx) => {
  await ctx.reply("Done", {
    reply_parameters: { message_id: ctx.message.message_id, allow_sending_without_reply: true },
  });
});

Catch the error where the reply is optional

Where you cannot use the flag — a reply in another chat or topic — catch this one error, send without the reply, and raise everything else.

aiogram 3. Telegram’s 400 is TelegramBadRequest, with Telegram’s description in message[7][8]:

from aiogram.exceptions import TelegramBadRequest
from aiogram.types import ReplyParameters

try:
    await bot.send_message(chat_id, text, reply_parameters=ReplyParameters(message_id=reply_id))
except TelegramBadRequest as e:
    if "message to be replied not found" not in e.message:
        raise
    await bot.send_message(chat_id, text)

python-telegram-bot. Telegram’s 400 is BadRequest; the library removes Bad Request: and capitalizes the rest, so compare in lower case[12][13]:

from telegram import ReplyParameters
from telegram.error import BadRequest

try:
    await context.bot.send_message(chat_id, text, reply_parameters=ReplyParameters(message_id=reply_id))
except BadRequest as e:
    if "message to be replied not found" not in e.message.lower():
        raise
    await context.bot.send_message(chat_id, text)

grammY. API errors are GrammyError, with Telegram’s description[18]:

import { GrammyError } from "grammy";

try {
  await bot.api.sendMessage(chatId, text, { reply_parameters: { message_id: replyId } });
} catch (e) {
  if (!(e instanceof GrammyError && e.description.includes("message to be replied not found"))) throw e;
  await bot.api.sendMessage(chatId, text);
}

Telegraf. API errors are TelegramError, with a description getter[21]:

import { TelegramError } from "telegraf";

try {
  await bot.telegram.sendMessage(chatId, text, { reply_parameters: { message_id: replyId } });
} catch (e) {
  if (!(e instanceof TelegramError && e.description.includes("message to be replied not found"))) throw e;
  await bot.telegram.sendMessage(chatId, text);
}

Keep the chat, topic and message together

Reply with the library’s shortcut on the message you received (message.reply, ctx.reply with that message’s id), so the chat and topic come from the same message. If you store a message to reply to later, store its chat id, topic and message id together, and pass chat_id in reply_parameters when the reply goes to a different chat.

On Livops

This error happens while the bot runs, when it sends a reply; a deploy does not send your bot’s messages, so it can be green while a reply fails.

  • Logs. The error line is on the project’s Logs page, and livops logs <service> -f follows it from the terminal; see CLI. Log the chat_id, the topic and the message_id you replied to next to it, so you can tell a deleted message from an id from another chat. 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 — for example, replying to a stored message that has since been deleted — 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 is down until a deploy succeeds. See The app did not start.
  • Ship the fix with a push. Every git push to the project’s branch starts a new deploy; push the fix, 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 to be replied not found mean?

Your bot sent a message as a reply, and the Bot API server could not find the message it was meant to reply to. Usually it was deleted, or its message_id belongs to another chat or forum topic. Nothing was sent, not even the text without the reply.

How do I send the message even if the original was deleted?

Pass reply_parameters with the message_id and allow_sending_without_reply set to true. Telegram then sends a normal message when the original is gone. In aiogram you can make it the default with DefaultBotProperties, and in python-telegram-bot with Defaults.

Where did reply_to_message_id go?

Bot API 7.0, in December 2023, replaced the reply_to_message_id and allow_sending_without_reply parameters of the send methods with one field, reply_parameters. The Bot API server still reads the old parameters when reply_parameters is missing, but the documentation lists only reply_parameters.

Why does allow_sending_without_reply not help?

It is always false for a reply to a message in another chat or another forum topic, so a deleted message there still fails. The server also fails a reply in a supergroup or channel the bot is not a member of before it looks at the flag. And if you pass reply_parameters, a top-level allow_sending_without_reply is ignored.

How is it different from message to edit not found?

Both mean the server could not find a message by its id. Message to edit not found comes from the edit methods, when the bot changes a message already in the chat. Message to be replied not found comes from the send methods, when the bot sends a new message as a reply.

Is reply message not found the same error?

Yes, in older wording. The Bot API server's source said reply message not found when it was first published in 2020, later replied message not found, then message to reply not found from October 2023, and message to be replied not found since May 2024.

Sources

  1. Telegram Bot API — Making requests, sendMessage, ReplyParameters, Message (core.telegram.org). Checked .
  2. Telegram Bot API — Changelog (Bot API 7.0, Replies 2.0) (core.telegram.org). Checked .
  3. Telegram Bot API server source — telegram-bot-api/Client.cpp (raw.githubusercontent.com). Checked .
  4. Telegram Bot API server — commit 9a7a293 (31 October 2023), replied message renamed to message to reply (github.com). Checked .
  5. Telegram Bot API server — commit a5a1c50 (3 May 2024), message to reply renamed to message to be replied (github.com). Checked .
  6. Telegram Bot API server source as first published (3 November 2020) — telegram-bot-api/Client.cpp (github.com). Checked .
  7. aiogram source — aiogram/exceptions.py (raw.githubusercontent.com). Checked .
  8. aiogram source — aiogram/client/session/base.py (raw.githubusercontent.com). Checked .
  9. aiogram source — aiogram/types/reply_parameters.py (raw.githubusercontent.com). Checked .
  10. aiogram source — aiogram/client/default.py (raw.githubusercontent.com). Checked .
  11. aiogram source — aiogram/types/message.py (raw.githubusercontent.com). Checked .
  12. python-telegram-bot source — telegram/error.py (raw.githubusercontent.com). Checked .
  13. python-telegram-bot source — telegram/request/_baserequest.py (raw.githubusercontent.com). Checked .
  14. python-telegram-bot source — telegram/_reply.py (ReplyParameters) (raw.githubusercontent.com). Checked .
  15. python-telegram-bot source — telegram/_bot.py (send_message) (raw.githubusercontent.com). Checked .
  16. python-telegram-bot source — telegram/ext/_defaults.py (raw.githubusercontent.com). Checked .
  17. python-telegram-bot source — telegram/ext/_applicationbuilder.py (raw.githubusercontent.com). Checked .
  18. grammY source — src/core/error.ts (raw.githubusercontent.com). Checked .
  19. grammY source — src/context.ts (raw.githubusercontent.com). Checked .
  20. grammY types source — message.ts (ReplyParameters) (raw.githubusercontent.com). Checked .
  21. Telegraf source — src/core/network/error.ts (raw.githubusercontent.com). Checked .
  22. Telegraf source — src/context.ts (raw.githubusercontent.com). Checked .
  23. Telegraf 4.16.3 — package.json (github.com). Checked .
  24. @telegraf/types v7.1.0 source — message.ts (ReplyParameters) (github.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