diff --git a/pyrogram/methods/users/__init__.py b/pyrogram/methods/users/__init__.py index b1b8bc71..5f1ddf7e 100644 --- a/pyrogram/methods/users/__init__.py +++ b/pyrogram/methods/users/__init__.py @@ -17,6 +17,7 @@ # along with Pyrogram. If not, see . from .block_user import BlockUser +from .check_username import CheckUsername from .delete_profile_photos import DeleteProfilePhotos from .get_chat_photos import GetChatPhotos from .get_chat_photos_count import GetChatPhotosCount @@ -34,6 +35,7 @@ from .update_status import UpdateStatus class Users( BlockUser, + CheckUsername, GetCommonChats, GetChatPhotos, SetProfilePhoto, diff --git a/pyrogram/methods/users/check_username.py b/pyrogram/methods/users/check_username.py new file mode 100644 index 00000000..977e3f50 --- /dev/null +++ b/pyrogram/methods/users/check_username.py @@ -0,0 +1,51 @@ +# Pyrogram - Telegram MTProto API Client Library for Python +# Copyright (C) 2017-present Dan +# +# This file is part of Pyrogram. +# +# Pyrogram is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pyrogram is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with Pyrogram. If not, see . + +import pyrogram +from pyrogram import raw + + +class CheckUsername: + async def check_username( + self: "pyrogram.Client", + username: str + ) -> bool: + """Check if a username is available. + + .. include:: /_includes/usable-by/users.rst + + Parameters: + username (``str``): + Username to check. + + Returns: + ``bool``: True on success. + + Example: + .. code-block:: python + + await app.check_username("username") + """ + + return bool( + await self.invoke( + raw.functions.account.CheckUsername( + username=username + ) + ) + )