1616# You should have received a copy of the GNU Lesser General Public License
1717# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
1818
19+ from datetime import datetime
1920from typing import Union
2021
21- from pyrogram import raw
22+ from pyrogram import raw , utils
2223from pyrogram import types
2324from pyrogram .scaffold import Scaffold
2425
@@ -29,7 +30,7 @@ async def restrict_chat_member(
2930 chat_id : Union [int , str ],
3031 user_id : Union [int , str ],
3132 permissions : "types.ChatPermissions" ,
32- until_date : int = 0
33+ until_date : datetime = datetime . fromtimestamp ( 0 )
3334 ) -> "types.Chat" :
3435 """Restrict a user in a supergroup.
3536
@@ -47,26 +48,26 @@ async def restrict_chat_member(
4748 permissions (:obj:`~pyrogram.types.ChatPermissions`):
4849 New user permissions.
4950
50- until_date (``int` `, *optional*):
51- Date when the user will be unbanned, unix time .
51+ until_date (:py:obj:`~datetime.datetime `, *optional*):
52+ Date when the user will be unbanned.
5253 If user is banned for more than 366 days or less than 30 seconds from the current time they are
53- considered to be banned forever. Defaults to 0 (ban forever).
54+ considered to be banned forever. Defaults to epoch (ban forever).
5455
5556 Returns:
5657 :obj:`~pyrogram.types.Chat`: On success, a chat object is returned.
5758
5859 Example:
5960 .. code-block:: python
6061
61- from time import time
62+ from datetime import datetime, timedelta
6263
6364 from pyrogram.types import ChatPermissions
6465
6566 # Completely restrict chat member (mute) forever
6667 app.restrict_chat_member(chat_id, user_id, ChatPermissions())
6768
6869 # Chat member muted for 24h
69- app.restrict_chat_member(chat_id, user_id, ChatPermissions(), int(time( ) + 86400 ))
70+ app.restrict_chat_member(chat_id, user_id, ChatPermissions(), datetime.now( ) + timedelta(days=1 ))
7071
7172 # Chat member can only send text messages
7273 app.restrict_chat_member(chat_id, user_id, ChatPermissions(can_send_messages=True))
@@ -76,7 +77,7 @@ async def restrict_chat_member(
7677 channel = await self .resolve_peer (chat_id ),
7778 participant = await self .resolve_peer (user_id ),
7879 banned_rights = raw .types .ChatBannedRights (
79- until_date = until_date ,
80+ until_date = utils . datetime_to_timestamp ( until_date ) ,
8081 send_messages = not permissions .can_send_messages ,
8182 send_media = not permissions .can_send_media_messages ,
8283 send_stickers = not permissions .can_send_other_messages ,
0 commit comments