Change destination of author link to BuddyPress member profile

The following codes worked. I added to my child theme’s functions.php

  add_filter( 'author_link', 'change_author_link', 10, 1  );

  function change_author_link($link) {
   $username=get_the_author_meta('user_nicename');


  $link = 'http://example.com/members/' . $username;
   return $link;
 }

error code: 523