From "the string is initially at rest", we know that $\partial_{t}y(x,0) = 0$. From "along the $x$-axis", we have $y(x,0) = 0$. So our initial-boundary-value problem is
\begin{align}
y_{tt} &= \nu^{2}y_{xx} -g, \qquad
y(x,0) = 0, \qquad
\partial_{t}y(x,0) = 0, \qquad
y(0,t) = y(\pi, t) = 0
\end{align}
You can solve the inhomogeneous part of the equation by taking $y_{p}(x,t)$ to be a second order polynomial in $x$ and $t$, (which will differentiate down to a constant under the action of $\partial_{t}^{2} - \nu^{2}\partial_{x}^{2}$, i.e., take $y_{p}(x,t) = a_{20}t^{2}+a_{10}t + a_{11}tx + a_{01}x + a_{02}x^2 + a_{00}$. The conditions $y(0,t) = y(\pi,t) = 0$ imply that $y_{p}(x,t) = cx(x-\pi)$. Hitting this with $\partial_{t}^{2} - \nu^{2}\partial_{x}^{2}$ and setting the result $=-g$ shows $c = \frac{g}{2\nu^{2}}$, i.e.,
\begin{align}
y(x,t) = y_{h}(x,t) - \frac{g}{2\nu^{2}}x(\pi-x),
\end{align}
where $y_{h}$ solves
\begin{align}
\partial_{t}^{2}y_{h} &= \nu^{2}\partial_{x}^{2}y_{h}, \qquad
y_{h}(x,0) = 0, \qquad
\partial_{t}y_{h}(x,0) = 0, \qquad
y_{h}(0,t) = y_{h}(\pi, t) = 0
\end{align}
By separation of variables and application of boundary conditions, we see that the eigenfunctions are of the form $\cos(\nu mt)\sin(mx)$, so
\begin{align}
y(x,t) = \sum_{m=1}^{\infty} a_{m}\cos(\nu mt)\sin(mx) - \frac{g}{2\nu^{2}}x(\pi-x).
\end{align}
Since $y(x,0) = 0$, then
\begin{align}
\sum_{m=1}^{\infty} a_{m}\sin(mx) = \frac{g}{2\nu^{2}}x(\pi-x)
\end{align}
Multiplication by $\sin(\ell x)$ and integration over $[0,\pi]$ gives
\begin{align}
a_{\ell} &= \frac{g}{\pi\nu^{2}}\int_{0}^{\pi} x(\pi -x) \sin(\ell x), \mathrm{d}x \\
&=\frac{2g(1-(-1)^{\ell})}{\pi \nu^2 \ell^3}
\end{align}
so that $a_{2n} = 0$ and $a_{2n-1} = \frac{4g}{\pi\nu^{2}(2n-1)^{3}}$, giving
\begin{align}
y(x,t) = \sum_{n=1}^{\infty} \frac{4g}{\pi\nu^{2}(2n-1)^{3}}\cos((2n-1)\nu t)\sin((2n-1)x) - \frac{g}{2\nu^{2}}x(\pi-x).
\end{align}