Ban a user from a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the group on their own using invite links, etc., unless unbanned first. You must be an administrator in the chat for this to work and must have the appropriate admin rights.
In regular groups (non-supergroups), this method will only work if the “All Members Are Admins” setting is off in the target group. Otherwise members may only be removed by the group’s creator or by the member that added them.Usable by Users Bots
str) – Unique identifier (int) or username (str) of the target chat.
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).
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).
bool– On success, a service message will be returned (when applicable), otherwise, in case a message object couldn’t be returned, True is returned.
from datetime import datetime, timedelta # Ban chat member forever await app.ban_chat_member(chat_id, user_id) # Ban chat member and automatically unban after 24h await app.ban_chat_member(chat_id, user_id, datetime.now() + timedelta(days=1))