add_chat_to_community()

Client.add_chat_to_community()

Add a chat to an existing community.

Usable by Users Bots
Parameters:
  • community_id (int) – The raw community ID (as returned by linked_community_id on Chat or by get_joined_communities()). Note: this is not the -100-prefixed channel ID.

  • chat_id (int | str) – The chat or peer to add to the community.

  • hidden (bool, optional) – Pass True to add the chat as hidden (not visible in the community sidebar). Defaults to False (visible).

Returns:

bool – True on success.

Raises:
  • PeerLinkNotModified – The chat is already linked to the community.

  • ChatAdminRequired – The user is not an admin of the community or the chat.

Example

# Get the community ID from a linked chat
chat = await app.get_chat(my_channel_id)
community_id = chat.linked_community_id

# Add visible
await app.add_chat_to_community(community_id, chat_id)

# Add hidden
await app.add_chat_to_community(community_id, chat_id, hidden=True)