|
| 1 | +# Pyrogram - Telegram MTProto API Client Library for Python |
| 2 | +# Copyright (C) 2017-present Dan <https://github.com/delivrance> |
| 3 | +# |
| 4 | +# This file is part of Pyrogram. |
| 5 | +# |
| 6 | +# Pyrogram is free software: you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU Lesser General Public License as published |
| 8 | +# by the Free Software Foundation, either version 3 of the License, or |
| 9 | +# (at your option) any later version. |
| 10 | +# |
| 11 | +# Pyrogram is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU Lesser General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU Lesser General Public License |
| 17 | +# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | +from typing import Optional |
| 20 | + |
| 21 | +import pyrogram |
| 22 | +from pyrogram import raw |
| 23 | + |
| 24 | + |
| 25 | +class CheckUsername: |
| 26 | + async def check_username( |
| 27 | + self: "pyrogram.Client", |
| 28 | + username: Optional[str] |
| 29 | + ) -> bool: |
| 30 | + """check username. |
| 31 | +
|
| 32 | + This method only works for users, not bots. Bot usernames must be changed via Bot Support or by recreating |
| 33 | + them from scratch using BotFather. To set a channel or supergroup username you can use |
| 34 | + :meth:`~pyrogram.Client.check_username`. |
| 35 | +
|
| 36 | + .. include:: /_includes/usable-by/users.rst |
| 37 | +
|
| 38 | + Parameters: |
| 39 | + username (``str`` | ``None``): |
| 40 | + Username to set. "" (empty string) or None to remove it. |
| 41 | +
|
| 42 | + Returns: |
| 43 | + ``bool``: True on success. |
| 44 | +
|
| 45 | + Example: |
| 46 | + .. code-block:: python |
| 47 | +
|
| 48 | + await app.check_username("username") |
| 49 | + """ |
| 50 | + |
| 51 | + return bool( |
| 52 | + await self.invoke( |
| 53 | + raw.functions.account.CheckUsername( |
| 54 | + username=username or "" |
| 55 | + ) |
| 56 | + ) |
| 57 | + ) |
0 commit comments