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

Bad Request: message text is empty — Telegram bot error and how to fix it

Bad Request: message text is empty means your bot called sendMessage or editMessageText with no text: an empty string, a variable that came back empty, or no text parameter at all. Text made only of spaces and line breaks fails too, as text must be non-empty. Check the text before you send, and send a fallback line instead.

By Livops team, the people who build and run LivopsUpdated

The error, as the Telegram Bot API returns it when a message has no text:

{"ok":false,"error_code":400,"description":"Bad Request: message text is empty"}

Each library wraps it in its own words:

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

This page explains what the error means and its close relative text must be non-empty, lists where an empty text comes from, and shows the fix — check the text before you send and fall back to a short line — in aiogram, python-telegram-bot, grammY and Telegraf. It also covers the other end of the rule, the 4096-character limit, and ends with how to find the empty value on Livops.

What does the error mean?

sendMessage sends a text message, and its text parameter is required: 1-4096 characters after entities parsing[1]. editMessageText has the same rule for the new text of a message[1]. A text message cannot be empty.

The Bot API server checks this before anything is sent. When text is an empty string — or the parameter is missing, which it reads the same way — it answers Message text is empty with code 400, and turns that into Bad Request: message text is empty[2]. Nothing reached the chat.

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.

The close relative: text must be non-empty

The first check only asks whether the string is empty. Text that is not empty can still have nothing to show:

{"ok":false,"error_code":400,"description":"Bad Request: text must be non-empty"}

Before a message is sent, TDLib — the library the Bot API server is built on — trims spaces and line breaks from the start and the end of the text. If nothing is left, it refuses the text with Text must be non-empty[3], which reaches your bot as Bad Request: text must be non-empty[2]. Only the space and the line break count as blank here[3].

So "" gives message text is empty, and " " or "\n\n" gives text must be non-empty. Both have the same cause and the same fix.

Where the empty text comes from, most common first

1. A variable that came back empty

The text is built from something that had nothing in it:

  • a database query or an API call that returned no rows, joined into a message: "\n".join(lines) of an empty list is "";
  • a dictionary lookup with an empty default, such as texts.get(lang, "") for a language you did not translate;
  • an AI model’s reply that came back empty, or only whitespace, sent as it is;
  • a file or template that rendered nothing because a condition hid every line.

In JavaScript, a text that is undefined may not be sent at all: a field with an undefined value is dropped when an object becomes JSON. The request then reaches Telegram with no text, which the Bot API server reads as empty[2].

2. Text made of spaces and line breaks

A template with a blank line for each missing field, or a message padded with "\n" for spacing, ends up as whitespace only when every field is missing. That is the text must be non-empty case above[3].

3. Markup with no visible text

With parse_mode set, the Bot API server turns HTML, Markdown or MarkdownV2 into plain text plus formatting entities before the message is sent[2], and the 1-4096 rule counts the text after that step[1]. <b></b> with HTML, or <b>{name}</b> where name is empty, is not empty as a string, but there is no text left once the tags are taken out. Telegram refuses it as empty. If the markup itself is broken, you get a different error: see can’t parse entities.

4. A caption sent as text

A photo, video or document can have no caption: a caption is optional, 0-1024 characters[1]. A text message cannot. Code that sends “the caption” with sendMessage when a file is missing, or that edits a message’s text with an empty string, hits this error.

How to fix it

Check the text before you send

The fix is not to make the request. Check the text where it is built, and send a short fallback line when there is nothing to say. Treat whitespace as empty too, because Telegram does.

def non_empty(text: str | None, fallback: str = "Nothing found.") -> str:
    if text is None or not text.strip(" \n"):
        return fallback
    return text
function nonEmpty(text: string | undefined | null, fallback = "Nothing found."): string {
  return text && text.replace(/[ \n]/g, "") !== "" ? text : fallback;
}

With parse_mode, check the data, not the finished markup: if not items: before you build <b>…</b> around them. Markup with nothing inside it is hard to spot once it is built.

Log the value that came back empty

The fallback keeps the chat working; the log tells you why the text was empty. Log what the text was built from — the user, the query, the rows — at the point where you fall back:

if not lines:
    logging.warning("empty reply for user %s, query %r", message.from_user.id, query)
    await message.answer("Nothing found.")
    return
await message.answer("\n".join(lines))

Catch the error where you cannot check

When the text comes from somewhere you do not control, 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 message.answer(text)
except TelegramBadRequest as e:
    if "message text is empty" not in e.message and "text must be non-empty" not in e.message:
        raise
    logging.warning("empty text for chat %s", message.chat.id)

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

from telegram.error import BadRequest

try:
    await update.message.reply_text(text)
except BadRequest as e:
    msg = e.message.lower()
    if "message text is empty" not in msg and "text must be non-empty" not in msg:
        raise
    logging.warning("empty text for chat %s", update.effective_chat.id)

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

import { GrammyError } from "grammy";

try {
  await ctx.reply(text);
} catch (e) {
  const empty = e instanceof GrammyError &&
    /message text is empty|text must be non-empty/.test(e.description);
  if (!empty) throw e;
  console.warn("empty text for chat", ctx.chat?.id);
}

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

import { TelegramError } from "telegraf";

try {
  await ctx.reply(text);
} catch (e) {
  const empty = e instanceof TelegramError &&
    /message text is empty|text must be non-empty/.test(e.description);
  if (!empty) throw e;
  console.warn("empty text for chat", ctx.chat?.id);
}

The other end of the rule: 4096 characters

The same parameter has an upper limit: 4096 characters after entities parsing[1]. Tags and Markdown symbols do not count; the visible text does. A longer text is refused with a different error, not this one.

Split long text before you format it, so no tag is cut in half — a cut tag gives can’t parse entities instead. Split at line breaks, keep each part well under the limit, and never send a part that ended up empty:

def split_text(text: str, limit: int = 4000) -> list[str]:
    parts, current = [], ""
    for line in text.split("\n"):
        while len(line) > limit:  # one very long line
            parts.append(current)
            current = ""
            parts.append(line[:limit])
            line = line[limit:]
        if len(current) + len(line) + 1 > limit:
            parts.append(current)
            current = ""
        current = f"{current}\n{line}" if current else line
    parts.append(current)
    return [p for p in parts if p.strip(" \n")]

Is an empty text ever allowed?

Once: sendMessageDraft, which streams a partial message to a user while it is being generated, takes 0-4096 characters, and an empty text shows a “Thinking…” placeholder[1]. The draft is a temporary preview; the finished answer must still be sent with sendMessage[1] — and that one must not be empty. An AI bot that streams a draft and then sends an empty final answer gets exactly this error.

On Livops

This error happens while the bot runs, when a handler builds an empty message; the deploy can be green while one command answers nothing.

  • Logs. The error line, and the warning you log with the value that came back empty, are on the project’s Logs page. livops logs <service> -f follows them 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 — say, a startup message to an admin chat with an empty text — 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 check and the fallback, 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 text is empty mean in a Telegram bot?

The bot called sendMessage or editMessageText and the text parameter was an empty string or was not sent at all. A text message must have 1 to 4096 characters after entities parsing, so Telegram refuses the request with 400 Bad Request and nothing is sent.

Why do I get text must be non-empty instead?

It is the same mistake one step later. Your text was not empty, but it held nothing except spaces and line breaks, or markup with no visible text in it. Telegram trims that away, finds nothing left and refuses the message with Bad Request: text must be non-empty.

Can I send an empty message on purpose?

No, not with sendMessage: the text needs at least one visible character. If you want a placeholder while an answer is being generated, sendMessageDraft accepts an empty text and shows Thinking until you send the real message with sendMessage.

Can a photo be sent without a caption?

Yes. A caption is optional and may be 0 to 1024 characters, so an empty caption is not an error. Only the text of a text message must be non-empty.

What is the longest message a bot can send?

4096 characters after entities parsing, which means counting the visible text, not the HTML or Markdown tags around it. Longer text is refused with a different error, so split it into several messages before you send.

Is it safe to just catch the error and ignore it?

Catching it keeps the bot running, but the user still gets no answer. Check the text before you send and fall back to a short line such as Nothing found, and log the value that came back empty so you can fix the code that produced it.

Sources

  1. Telegram Bot API — Making requests, sendMessage, sendMessageDraft, editMessageText, sendPhoto (core.telegram.org). Checked .
  2. Telegram Bot API server source — telegram-bot-api/Client.cpp (raw.githubusercontent.com). Checked .
  3. TDLib source — td/telegram/MessageEntity.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. python-telegram-bot source — telegram/error.py (raw.githubusercontent.com). Checked .
  7. python-telegram-bot source — telegram/request/_baserequest.py (raw.githubusercontent.com). Checked .
  8. grammY source — src/core/error.ts (raw.githubusercontent.com). Checked .
  9. 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 bot

Got a question? — @livops_uz