Working with Chats and Channels


These examples assume you have read The Full API.

Joining a chat or channel

Note that Chat are normal groups, and Channel are a special form of Chat, 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 import JoinChannelRequest
await client(JoinChannelRequest(channel))

# In the same way, you can also leave such channel
from import LeaveChannelRequest
await 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:, you already have enough information to join! The part after the, this is, AAAAAFFszQPyPEZ7wgxLtd on this example, is the hash of the chat or channel. Now you can use ImportChatInviteRequest as follows:

from import ImportChatInviteRequest
updates = await 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, or InviteToChannelRequest for channels:

# For normal chats
from 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(
    fwd_limit=10  # Allow the user to see the 10 last messages

# For channels (which includes megagroups)
from import InviteToChannelRequest

await client(InviteToChannelRequest(

Admin Permissions

Giving or revoking admin permissions can be done with the EditAdminRequest:

from import EditAdminRequest
from import ChatAdminRights

# You need both the channel and who to grant permissions
# They can either be channel/user or input channel/input user.
# ChatAdminRights is a list of granted permissions.
# Set to True those you want to give.
rights = ChatAdminRights(
# Equivalent to:
#     rights = ChatAdminRights(
#         change_info=True,
#         delete_messages=True,
#         pin_messages=True
#     )

# Once you have a ChatAdminRights, invoke it
await client(EditAdminRequest(channel, user, rights))

# User will now be able to change group info, delete other people's
# messages and pin messages.
# In a normal chat, you should do this instead:
from import EditChatAdminRequest

await client(EditChatAdminRequest(chat_id, user, is_admin=True))


Thanks to @Kyle2142 for pointing out that you cannot set all parameters to True to give a user full permissions, as not all permissions are related to both broadcast channels/megagroups.

E.g. trying to set post_messages=True in a megagroup will raise an error. It is recommended to always use keyword arguments, and to set only the permissions the user needs. If you don’t need to change a permission, it can be omitted (full list here).

Restricting Users

Similar to how you give or revoke admin permissions, you can edit the banned rights of a user through EditBannedRequest and its parameter ChatBannedRights:

from import EditBannedRequest
from import ChatBannedRights

from datetime import datetime, timedelta

# Restricting a user for 7 days, only allowing view/send messages.
# Note that it's "reversed". You must set to `True` the permissions
# you want to REMOVE, and leave as `None` those you want to KEEP.
rights = ChatBannedRights(

# The above is equivalent to
rights = ChatBannedRights( + timedelta(days=7),

await client(EditBannedRequest(channel, user, rights))

You can use a datetime.datetime object for until_date=, a datetime.timedelta or even a Unix timestamp. Note that if you ban someone for less than 30 seconds or for more than 366 days, Telegram will consider the ban to actually last forever. This is officially documented under

Kicking a member

Telegram doesn’t actually have a request to kick a user from a group. Instead, you need to restrict them so they can’t see messages. Any date is enough:

from import EditBannedRequest
from import ChatBannedRights

await client(EditBannedRequest(
    channel, user, ChatBannedRights(

Increasing View Count in a Channel

It has been asked quite a few times (really, many), and while I don’t understand why so many people ask this, the solution is to use GetMessagesViewsRequest, setting increment=True:

# 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(

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.