Channel Members
Channel members are users who have been added to a channel and can participate in conversations. This page covers how to manage channel membership, including adding and removing members, controlling message history visibility, and managing member roles.
Adding and Removing Members
Adding Members
Using the addMembers() method adds the given users as members to a channel.
from getstream.models import ChannelMemberRequest
channel.update(
add_members=[
ChannelMemberRequest(user_id="thierry"),
ChannelMemberRequest(user_id="josh"),
],
)Note: You can only add/remove up to 100 members at once.
Members can also be added when creating a channel:
const channel = client.channel("messaging", randomID, {
members: [
{ user_id: "james_bond", code_name: "007" },
{ user_id: "alec_trevelyan", code_name: "006" },
],
});
await channel.create();Removing Members
Using the removeMembers() method removes the given users from the channel.
channel.update(remove_members=["tommaso"])Removal and Channel Access
Removing a member ends their membership. It does not always end their access to the channel.
When you remove a member, within the same request:
- Their membership ends, so they stop receiving notifications, push and unread counts for the channel.
- Stream attempts to unsubscribe every device that user has connected, not only the active one.
The unsubscribe is best-effort. A successful response confirms the membership change. It does not guarantee that every device has already stopped receiving the channel, because a presence lookup or an unsubscribe can fail without failing the request.
Clients that lose read access are then disconnected from the channel, and may receive a channel.kicked event. That event is not guaranteed, since a client already unsubscribed by the step above is no longer enumerated. Use notification.removed_from_channel to handle membership removal on the client. Events already in flight may still arrive.
Whether a removed member loses read access depends on your channel type's permissions, not on the removal. This matters in two common cases:
- On channel types that grant read access to non-members, such as
livestream, membership grants no extra read permission. - The user who created the channel can read it as its owner, on any channel type, independently of membership.
In both cases the removed user keeps receiving the channel and can start watching it again. To revoke read access, change the channel type's permissions so the resulting role cannot read the channel.
Banning is not a substitute. A channel ban stops the user sending messages, but it does not remove read access or unsubscribe watchers, so a banned user whose role still grants read can keep watching the channel.
Leaving a Channel
Users can leave a channel without moderator-level permissions. Ensure channel members have the Leave Own Channel permission enabled.
// Remove own channel membership
await channel.removeMembers(["my_user_id"]);You can familiarize yourself with all permissions in the Permissions section.
Hide History
When members join a channel, you can specify whether they have access to the channel's message history. By default, new members can see the history. Set hide_history to true to hide it for new members.
from getstream.models import ChannelMemberRequest
channel.update(
add_members=[ChannelMemberRequest(user_id="thierry")],
hide_history=True,
)Hide History Before a Specific Date
Alternatively, hide_history_before can be used to hide any history before a given timestamp while giving members access to later messages. The value must be a timestamp in the past in RFC 3339 format. If both parameters are defined, hide_history_before takes precedence over hide_history.
from datetime import datetime, timedelta, timezone
from getstream.models import ChannelMemberRequest
cutoff = datetime.now(timezone.utc) - timedelta(days=7) # Last 7 days
channel.update(
add_members=[ChannelMemberRequest(user_id="thierry")],
hide_history_before=cutoff,
)System Message Parameter
You can optionally include a message object when adding or removing members that client-side SDKs will use to display a system message. This works for both adding and removing members.
from getstream.models import ChannelMemberRequest, MessageRequest
channel.update(
add_members=[
ChannelMemberRequest(user_id="tommaso"),
ChannelMemberRequest(user_id="josh"),
],
message=MessageRequest(
text="Tommaso joined the channel.",
user_id="tommaso",
),
)Adding and Removing Moderators
Using the addModerators() method adds the given users as moderators (or updates their role to moderator if already members), while demoteModerators() removes the moderator status.
Add Moderators
channel.update(add_moderators=["thierry", "josh"])Remove Moderators
channel.update(demote_moderators=["tommaso"])These operations can only be performed server-side, and a maximum of 100 moderators can be added or removed at once.
Member Custom Data
Custom data can be added at the channel member level. This is useful for storing member-specific information that is separate from user-level data. Ensure custom data does not exceed 5KB.
Adding Custom Data
// Add custom data while creating the channel
const channel = client.channel("messaging", randomID, {
members: [
{ user_id: "userid1", key1: "value1" },
{ user_id: "userid2", key1: "value1" },
{ user_id: "userid3", key2: "value2" },
],
});
// Add custom data with addMembers method
await channel.addMembers([{ user_id: "userid1", key1: "value1" }]);Updating Member Data
Channel members can be partially updated. Only custom data and channel roles are eligible for modification. You can set or unset fields, either separately or in the same call.
user_id = "amy"
# Set some fields
response = channel.update_member_partial(user_id=user_id, set={"hat": "blue"})
# Unset some fields
response = channel.update_member_partial(user_id=user_id, unset=["hat"])
# Set and unset in the same call
response = channel.update_member_partial(user_id=user_id, set={"color": "red"}, unset=["hat"])