Telegram · 403

Telegram 403: bot was blocked by the user

Not a bug in your bot. The person on the other end has blocked it, deleted their account, or never started a chat with it. What matters is how your code reacts.

← All errors

What you are seeing

Bot API

Forbidden: bot was blocked by the user

Bot API

Forbidden: bot can't initiate conversation with a user

Bot API

Forbidden: user is deactivated

What each message means

"Bot was blocked by the user": they pressed Stop and Block, or blocked it from their chat list. The bot cannot message them again until they unblock it and press Start.

"Bot can't initiate conversation with a user": a bot may only message someone who has started a chat with it first. You cannot message a user just because you know their ID.

"User is deactivated": the account has been deleted. Remove it from anything you store.

In groups, "bot was kicked from the group chat" is the same idea.

Handle it, do not crash on it

A bot that sends to a list of users — reminders, broadcasts, subscriptions — will meet these every day. If one failed send throws out of your loop, everyone after that user misses out. Catch the error per user, mark them inactive, and carry on.

python-telegram-bot

from telegram.error import Forbidden

for user_id in subscribers:
    try:
        await context.bot.send_message(user_id, text)
    except Forbidden:
        mark_inactive(user_id)

grammY

const { GrammyError } = require('grammy');

for (const userId of subscribers) {
    try {
        await bot.api.sendMessage(userId, text);
    } catch (error) {
        if (error instanceof GrammyError && error.error_code === 403) markInactive(userId);
        else throw error;
    }
}

FAQ

Questions

Can I tell when someone blocks the bot, without sending anything?

Yes. Telegram sends a my_chat_member update when a user blocks or unblocks the bot, with the new status "kicked" or "member". Handle it to keep your list up to date as it happens.