mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 09:26:37 +03:00
Add information to join a private chat or channel
parent
778a01c9e1
commit
4a79c967dc
29
Joining-a-chat-or-channel.md
Normal file
29
Joining-a-chat-or-channel.md
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
Note that [`Chat`](https://lonamiwebs.github.io/Telethon/constructors/chat.html)s are normal groups, and [`Channel`](https://lonamiwebs.github.io/Telethon/constructors/channel.html)s are a special form of [`Chat`](https://lonamiwebs.github.io/Telethon/types/chat.html)s, which can also be super-groups if their `megagroup` member is `True`.
|
||||||
|
|
||||||
|
## Joining a public channel
|
||||||
|
|
||||||
|
Once you have the [entity](Retrieving-an-entity) of the channel you want to join to, you can make use of the [`JoinChannelRequest`](https://lonamiwebs.github.io/Telethon/methods/channels/join_channel.html) to join such channel:
|
||||||
|
|
||||||
|
```python
|
||||||
|
from telethon.tl.functions.channels import JoinChannelRequest
|
||||||
|
from telethon.helpers import get_input_peer
|
||||||
|
|
||||||
|
input_channel = get_input_peer(channel)
|
||||||
|
client.invoke(JoinChannelRequest(input_channel))
|
||||||
|
|
||||||
|
# In the same way, you can also leave such channel
|
||||||
|
from telethon.tl.functions.channels import LeaveChannelRequest
|
||||||
|
client.invoke(LeaveChannelRequest(input_channel))
|
||||||
|
```
|
||||||
|
|
||||||
|
For more on channels, check the [`channels` namespace](https://lonamiwebs.github.io/Telethon/methods/channels/index.html).
|
||||||
|
|
||||||
|
## 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`](https://lonamiwebs.github.io/Telethon/methods/messages/import_chat_invite.html) as follows:
|
||||||
|
|
||||||
|
```python
|
||||||
|
from telethon.tl.functions.messages import ImportChatInviteRequest
|
||||||
|
|
||||||
|
updates = client.invoke(ImportChatInviteRequest('AAAAAEHbEkejzxUjAUCfYg'))
|
||||||
|
```
|
|
@ -1,15 +0,0 @@
|
||||||
Once you have the [entity](Retrieving-an-entity) of the channel you want to join to, you can make use of the [`JoinChannelRequest`](https://lonamiwebs.github.io/Telethon/methods/channels/join_channel.html) to join such channel:
|
|
||||||
|
|
||||||
```python
|
|
||||||
from telethon.tl.functions.channels import JoinChannelRequest
|
|
||||||
from telethon.helpers import get_input_peer
|
|
||||||
|
|
||||||
input_channel = get_input_peer(channel)
|
|
||||||
client.invoke(JoinChannelRequest(input_channel))
|
|
||||||
|
|
||||||
# In the same way, you can also leave such channel
|
|
||||||
from telethon.tl.functions.channels import LeaveChannelRequest
|
|
||||||
client.invoke(LeaveChannelRequest(input_channel))
|
|
||||||
```
|
|
||||||
|
|
||||||
For more on channels, check the [`channels` namespace](https://lonamiwebs.github.io/Telethon/methods/channels/index.html).
|
|
Loading…
Reference in New Issue
Block a user