restrictChatMember method

Future<bool> restrictChatMember(
  1. dynamic chat_id,
  2. int user_id, {
  3. ChatPermissions? permissions,
  4. int? until_date,
})
inherited

Use this method to restrict a user in a supergroup

The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights. Pass True for all boolean parameters to lift restrictions from a user. Returns True on success.

https://core.telegram.org/bots/api#restrictchatmember

This method now takes the new user permissions in a single argument of the type ChatPermissions. The old way of passing parameters will keep working for a while for backward compatibility.

Implementation

Future<bool> restrictChatMember(dynamic chat_id, int user_id,
    {ChatPermissions? permissions, int? until_date}) async {
  if (chat_id is! String && chat_id is! int) {
    return Future.error(TelegramException(
        'Attribute \'chat_id\' can only be either type of String or int'));
  }
  var requestUrl = _apiUri('restrictChatMember');
  var body = <String, dynamic>{
    'chat_id': chat_id,
    'user_id': user_id,
    'permissions': permissions == null ? null : jsonEncode(permissions),
    'until_date': until_date,
  };
  return await HttpClient.httpPost(requestUrl, body: body);
}