Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Refer to get_participants2.py for more than 10.000 users.
"""
app = Client("my_account")
target = "pyrogramchat" # Target channel/supergroup
users = [] # List that will contain all the users of the target chat
limit = 200 # Amount of users to retrieve for each API call
offset = 0 # Offset starts at 0
app.start()
while True:
try:
participants = app.send(
functions.channels.GetParticipants(
channel=app.resolve_peer(target),
filter=types.ChannelParticipantsSearch(""), # Filter by empty string (search for all)
offset=offset,
limit=limit,
hash=0
)
)
except FloodWait as e:
# Very large channels will trigger FloodWait.
# When happens, wait X seconds before continuing
time.sleep(e.x)
continue
if not participants.participants:
break # No more participants left
user_id (``int`` | ``str``):
Unique identifier (int) or username (str) of the target user.
For a contact that exists in your Telegram address book you can use his phone number (str).
Returns:
``bool``: True on success.
Example:
.. code-block:: python
# Unban chat member right now
app.unban_chat_member(chat_id, user_id)
"""
self.send(
functions.channels.EditBanned(
channel=self.resolve_peer(chat_id),
user_id=self.resolve_peer(user_id),
banned_rights=types.ChatBannedRights(
until_date=0
)
)
)
return True
title (``str``):
The supergroup title.
description (``str``, *optional*):
The supergroup description.
Returns:
:obj:`Chat`: On success, a chat object is returned.
Example:
.. code-block:: python
app.create_supergroup("Supergroup Title", "Supergroup Description")
"""
r = self.send(
functions.channels.CreateChannel(
title=title,
about=description,
megagroup=True
)
)
return pyrogram.Chat._parse_chat(self, r.chats[0])
users = {i.id: i for i in r.users}
for member in members:
member = pyrogram.ChatMember._parse(self, member, users)
if isinstance(user, types.InputPeerSelf):
if member.user.is_self:
return member
else:
if member.user.id == user.user_id:
return member
else:
raise UserNotParticipant
elif isinstance(chat, types.InputPeerChannel):
r = self.send(
functions.channels.GetParticipant(
channel=chat,
user_id=user
)
)
users = {i.id: i for i in r.users}
return pyrogram.ChatMember._parse(self, r.participant, users)
else:
raise ValueError("The chat_id \"{}\" belongs to a user".format(chat_id))
Defaults to False.
Example:
.. code-block:: python
# Leave chat or channel
app.leave_chat(chat_id)
# Leave basic chat and also delete the dialog
app.leave_chat(chat_id, delete=True)
"""
peer = self.resolve_peer(chat_id)
if isinstance(peer, types.InputPeerChannel):
return self.send(
functions.channels.LeaveChannel(
channel=self.resolve_peer(chat_id)
)
)
elif isinstance(peer, types.InputPeerChat):
r = self.send(
functions.messages.DeleteChatUser(
chat_id=peer.chat_id,
user_id=types.InputPeerSelf()
)
)
if delete:
self.send(
functions.messages.DeleteHistory(
peer=peer,
max_id=0
.. code-block:: python
from time import time
# Ban chat member forever
app.kick_chat_member(chat_id, user_id)
# Kick chat member and automatically unban after 24h
app.kick_chat_member(chat_id, user_id, int(time.time() + 86400))
"""
chat_peer = self.resolve_peer(chat_id)
user_peer = self.resolve_peer(user_id)
if isinstance(chat_peer, types.InputPeerChannel):
r = self.send(
functions.channels.EditBanned(
channel=chat_peer,
user_id=user_peer,
banned_rights=types.ChatBannedRights(
until_date=until_date,
view_messages=True,
send_messages=True,
send_media=True,
send_stickers=True,
send_gifs=True,
send_games=True,
send_inline=True,
embed_links=True
)
)
)
else:
Raises:
ValueError: In case a chat id belongs to a user or chat.
Example:
.. code-block:: python
app.update_chat_username(chat_id, "new_username")
"""
peer = self.resolve_peer(chat_id)
if isinstance(peer, types.InputPeerChannel):
return bool(
self.send(
functions.channels.UpdateUsername(
channel=peer,
username=username or ""
)
)
)
else:
raise ValueError("The chat_id \"{}\" belongs to a user or chat".format(chat_id))
if can_send_polls:
send_messages = None
send_polls = None
if can_change_info:
change_info = None
if can_invite_users:
invite_users = None
if can_pin_messages:
pin_messages = None
r = self.send(
functions.channels.EditBanned(
channel=self.resolve_peer(chat_id),
user_id=self.resolve_peer(user_id),
banned_rights=types.ChatBannedRights(
until_date=until_date,
send_messages=send_messages,
send_media=send_media,
send_stickers=send_stickers,
send_gifs=send_gifs,
send_games=send_games,
send_inline=send_inline,
embed_links=embed_links,
send_polls=send_polls,
change_info=change_info,
invite_users=invite_users,
pin_messages=pin_messages
)
can_promote_members (``bool``, *optional*):
Pass True, if the administrator can add new administrators with a subset of his own privileges or
demote administrators that he has promoted, directly or indirectly (promoted by administrators that
were appointed by him).
Returns:
``bool``: True on success.
Example:
.. code-block:: python
# Promote chat member to supergroup admin
app.promote_chat_member(chat_id, user_id)
"""
self.send(
functions.channels.EditAdmin(
channel=self.resolve_peer(chat_id),
user_id=self.resolve_peer(user_id),
admin_rights=types.ChatAdminRights(
change_info=can_change_info or None,
post_messages=can_post_messages or None,
edit_messages=can_edit_messages or None,
delete_messages=can_delete_messages or None,
ban_users=can_restrict_members or None,
invite_users=can_invite_users or None,
pin_messages=can_pin_messages or None,
add_admins=can_promote_members or None,
),
rank=""
)
)
A custom title that will be shown to all members instead of "Owner" or "Admin".
Pass None or "" (empty string) to remove the custom title.
Returns:
``bool``: True on success.
Example:
.. code-block:: python
app.set_administrator_title(chat_id, user_id, "ฅ^•ﻌ•^ฅ")
"""
chat_id = self.resolve_peer(chat_id)
user_id = self.resolve_peer(user_id)
r = self.send(
functions.channels.GetParticipant(
channel=chat_id,
user_id=user_id
)
).participant
if isinstance(r, types.ChannelParticipantCreator):
admin_rights = types.ChatAdminRights(
change_info=True,
post_messages=True,
edit_messages=True,
delete_messages=True,
ban_users=True,
invite_users=True,
pin_messages=True,
add_admins=True,
)