These examples assume you have read The Full API.
from telethon.tl.functions.channels import JoinChannelRequest await client(JoinChannelRequest(channel)) # In the same way, you can also leave such channel from telethon.tl.functions.channels import LeaveChannelRequest await client(LeaveChannelRequest(input_channel))
For more on channels, check the channels namespace.
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 = await client(ImportChatInviteRequest('AAAAAEHbEkejzxUjAUCfYg'))
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, or InviteToChannelRequest for channels:
# For normal chats from telethon.tl.functions.messages import AddChatUserRequest # Note that ``user_to_add`` is NOT the name of the parameter. # It's the user you want to add (``user_id=user_to_add``). await client(AddChatUserRequest( chat_id, user_to_add, fwd_limit=10 # Allow the user to see the 10 last messages )) # For channels (which includes megagroups) from telethon.tl.functions.channels import InviteToChannelRequest await client(InviteToChannelRequest( channel, [users_to_add] ))
# Obtain `channel' through dialogs or through client.get_entity() or anyhow. # Obtain `msg_ids' through `.get_messages()` or anyhow. Must be a list. await client(GetMessagesViewsRequest( peer=channel, id=msg_ids, increment=True ))
Note that you can only do this once or twice a day per account, running this in a loop will obviously not increase the views forever unless you wait a day between each iteration. If you run it any sooner than that, the views simply won’t be increased.