Skip to content
This repository was archived by the owner on Dec 23, 2024. It is now read-only.

Commit 5bdfe17

Browse files
committed
feat: 新增检测用户名是否可用
1 parent 6916224 commit 5bdfe17

2 files changed

Lines changed: 60 additions & 1 deletion

File tree

pyrogram/methods/users/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from .set_username import SetUsername
3030
from .unblock_user import UnblockUser
3131
from .update_profile import UpdateProfile
32+
from .check_username import CheckUsername
3233

3334

3435
class Users(
@@ -44,6 +45,7 @@ class Users(
4445
UnblockUser,
4546
UpdateProfile,
4647
GetDefaultEmojiStatuses,
47-
SetEmojiStatus
48+
SetEmojiStatus,
49+
CheckUsername
4850
):
4951
pass
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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

Comments
 (0)