diff --git a/pyrogram/client/methods/chats/join_chat.py b/pyrogram/client/methods/chats/join_chat.py index c379bf03..66687115 100644 --- a/pyrogram/client/methods/chats/join_chat.py +++ b/pyrogram/client/methods/chats/join_chat.py @@ -16,6 +16,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with Pyrogram. If not, see . +from typing import Union + import pyrogram from pyrogram.api import functions, types from ...ext import BaseClient @@ -24,14 +26,14 @@ from ...ext import BaseClient class JoinChat(BaseClient): def join_chat( self, - chat_id: str + chat_id: Union[int, str] ): """Join a group chat or channel. Parameters: - chat_id (``str``): - Unique identifier for the target chat in form of a *t.me/joinchat/* link or username of the target - channel/supergroup (in the format @username). + chat_id (``int`` | ``str``): + Unique identifier for the target chat in form of a *t.me/joinchat/* link, a username of the target + channel/supergroup (in the format @username) or a chat id of a linked chat (channel or supergroup). Returns: :obj:`Chat`: On success, a chat object is returned. @@ -44,8 +46,11 @@ class JoinChat(BaseClient): # Join chat via invite link app.join_chat("https://t.me/joinchat/AAAAAE0QmSW3IUmm3UFR7A") + + # Join a linked chat + app.join_chat(app.get_chat("pyrogram").linked_chat.id) """ - match = self.INVITE_LINK_RE.match(chat_id) + match = self.INVITE_LINK_RE.match(str(chat_id)) if match: chat = self.send( diff --git a/pyrogram/client/types/user_and_chats/chat.py b/pyrogram/client/types/user_and_chats/chat.py index 03b7d76a..db2b3ef6 100644 --- a/pyrogram/client/types/user_and_chats/chat.py +++ b/pyrogram/client/types/user_and_chats/chat.py @@ -675,7 +675,7 @@ class Chat(Object): chat.join() Note: - This only works for public groups and channels that have set a username. + This only works for public groups, channels that have set a username or linked chats. Returns: :obj:`Chat`: On success, a chat object is returned. @@ -684,7 +684,7 @@ class Chat(Object): RPCError: In case of a Telegram RPC error. """ - return self._client.join_chat(self.username) + return self._client.join_chat(self.username or self.id) def leave(self): """Bound method *leave* of :obj:`Chat`.