<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def set_invite_only(self, invite_only):
 """Set how the room can be joined. Args: invite_only(bool):
 If True, users will have to be invited to join the room. If False, anyone who knows the room link can join. Returns: True if successful, False if not """

        join_rule = "invite" if invite_only else "public"
        try:
            self.client.api.set_join_rule(self.room_id, join_rule)
            self.invite_only = invite_only
            return True
        except MatrixRequestError:
            return False