def ban_member(self, chat, user_id=None, user=None):
"""Bans chat member
Args:
chat(int|str): chat ID or '@channel_name'
user_id(Optional[int]): user ID to be banned
user(Optional[:class:`telegram.User`]): user to be banned
Returns:
bool: ``True`` on success, ``False`` otherwise
Raises:
ValueError: if both ``user_id`` and ``user`` were (not) given
"""
if (user_id is None and user is None) or (user_id is not None and user is not None):
raise ValueError('Either `user_id` or `user` must be given')
if user is not None:
user_id = user.id
try:
self._bot.kick_chat_member(chat, user_id)
except TelegramError as e:
logger.exception('Exception was raised while kicking member', exc_info=e)
return False
return True
评论列表
文章目录