restrict_chat_member()¶
- Client.restrict_chat_member()¶
Restrict a user in a supergroup.
You must be an administrator in the supergroup for this to work and must have the appropriate admin rights. Pass True for all permissions to lift restrictions from a user.
Usable by Users Bots
- Parameters:¶
chat_id (
int
|str
) – Unique identifier (int) or username (str) of the target chat. You can also use chat public link in form of t.me/<username> (str).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). You can also use user profile link in form of t.me/<username> (str).permissions (
ChatPermissions
) – New user permissions.until_date (
datetime
, optional) – Date when the user will be unbanned. If user is banned for more than 366 days or less than 30 seconds from the current time they are considered to be banned forever. Defaults to epoch (ban forever).
- Returns:¶
Chat
– On success, a chat object is returned.
Example
from datetime import datetime, timedelta from pyrogram.types import ChatPermissions # Completely restrict chat member (mute) forever await app.restrict_chat_member(chat_id, user_id, ChatPermissions()) # Chat member muted for 24h await app.restrict_chat_member(chat_id, user_id, ChatPermissions(), datetime.now() + timedelta(days=1)) # Chat member can only send text messages await app.restrict_chat_member(chat_id, user_id, ChatPermissions(can_send_messages=True))