By the definition of matrix exponentiation,
$$A^k = \begin{cases} I_n, & \text{if } k=0 \\[1ex] A^{k-1}A, & \text{if } k\in \mathbb {N}_0 \\ \end{cases}$$
In my book, there's an exercise to do $D^k$, where $D$ is a diagonal matrix. In the solutions, though, they wrote
$$D^k=\operatorname{diag}(d_1^k, \dots , d_n^k)$$
Which one is correct?
Both are correct but they are two different topics.
$$A^k=\left\{ \begin{array}{c} I_n, if\, k=0 \\ A^{k-1}A, if\, k\in {\displaystyle \mathbb {N} }_0 \\ \end{array} \right.$$ is the definition of the matrix power $A^k$ in general.
On the other hand $$D^k=diag(d_1\,^k, ... , d_n\,^k)$$ is a special case where your matrix is a diagonal matrix.
There is no conflict because the second one is just the application of the first one to the diagonal matrix $$D=diag(d_1,d_2, ... , d_n)$$