Skip to main content
Glama

unban_user

Restore access to a Telegram chat by removing a user's ban status. Provide chat and user IDs to reverse previous moderation actions.

Instructions

Unban a previously banned user.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chat_idYes
user_idYes
only_if_bannedNo

Implementation Reference

  • Implementation of the unban_user MCP tool handler.
    async def unban_user(
        chat_id: int,
        user_id: int,
        only_if_banned: bool = True,
    ) -> UnbanUserResult:
        """Unban a previously banned user."""
        if not ctx.is_chat_allowed(chat_id):
            result = UnbanUserResult(ok=False, error=f"Chat {chat_id} is not allowed.")
            if ctx.audit_logger:
                ctx.audit_logger.log(
                    "unban_user",
                    {"chat_id": chat_id, "user_id": user_id},
                    result.ok,
                    result.error,
                )
            return result
    
        try:
            if ctx.rate_limiter:
                await ctx.rate_limiter.acquire()
            await ctx.bot.unban_chat_member(
                chat_id=chat_id,
                user_id=user_id,
                only_if_banned=only_if_banned,
            )
            result = UnbanUserResult(ok=True, user_id=user_id)
        except (TelegramBadRequest, TelegramForbiddenError) as exc:
            result = UnbanUserResult(ok=False, error=str(exc))
    
        if ctx.audit_logger:
            ctx.audit_logger.log(
                "unban_user",
                {"chat_id": chat_id, "user_id": user_id},
                result.ok,
                result.error,
            )
  • Result schema for unban_user tool.
    class UnbanUserResult(ToolResponse):
        user_id: int | None = None
  • Registration logic for unban_user tool within register_chat_tools.
    if allowed_tools is None or "unban_user" in allowed_tools:

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Py2755/aiogram-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server