Joining a chat or channel - LonamiWebs/Telethon GitHub Wiki

Note that Chats are normal groups, and Channels are a special form of Chats, which can also be super-groups if their megagroup member is True.

Joining a public channel

Once you have the entity of the channel you want to join to, you can make use of the JoinChannelRequest to join such channel:

from telethon.tl.functions.channels import JoinChannelRequest
client(JoinChannelRequest(channel))

# In the same way, you can also leave such channel
from telethon.tl.functions.channels import LeaveChannelRequest
client(LeaveChannelRequest(input_channel))

For more on channels, check the channels namespace.

Joining a private chat or channel

If all you have is a link like this one: https://t.me/joinchat/AAAAAFFszQPyPEZ7wgxLtd, you already have enough information to join! The part after the https://t.me/joinchat/, this is, AAAAAFFszQPyPEZ7wgxLtd on this example, is the hash of the chat or channel. Now you can use ImportChatInviteRequest as follows:

from telethon.tl.functions.messages import ImportChatInviteRequest
updates = client(ImportChatInviteRequest('AAAAAEHbEkejzxUjAUCfYg'))

Adding someone else to such chat or channel

If you don't want to add yourself, maybe because you're already in, you can always add someone else with the AddChatUserRequest, which use is very straightforward:

from telethon.tl.functions.messages import AddChatUserRequest

client(AddChatUserRequest(
    chat_id,
    user_to_add,
    fwd_limit=10  # allow the user to see the 10 last messages
))

Checking a link without joining

If you don't need to join but rather check whether it's a group or a channel, you can use the CheckChatInviteRequest, which takes in the hash of said channel or group.