In classical mechanics, there does not always exist a well-defined notion of temperature (it does not make sense to define the temperature for a single free particle). Quantum mechanics exhibits similar behavior.
Formally, we can define a thermal expectation value $\langle \rangle_\beta$ which means, for some observable $\mathcal{O}$,
$$\langle \mathcal{O} \rangle_\beta = \langle \mathcal{O} e^{-\beta H} \rangle $$
where $\langle \rangle$ is the usual expectation value in quantum mechanics, and $\beta$ is the inverse temperature (this definition should be properly normalized, which we will ignore for now). To understand what this means intuitively, we can expand the expectation value in the energy eigenbasis
$$\langle \mathcal{O} \rangle_\beta = \sum_n \langle n | \mathcal{O} | n\rangle e^{-\beta E_n} $$
What this means is that, for low temperature (large $\beta$), the $e^{-\beta E_n}$ term penalizes higher energy contributions, and the lower energy states contribute more to the thermal expectation value. If you're familiar with the notion of density matrices, you'll see that the thermal expectation value is just the expectation value for a system in the state $\rho = e^{-\beta H}$.
If you want to, you can take this as just the definition of what temperature means in quantum mechanics. If we want to talk about a quantum system at some inverse temperature $\beta$, we just replace all the normal expectation values with thermal expectation values. But this doesn't really explain why this definition is relevant (similar to how we sometimes just take the classical laws of thermodynamics as a given, without a statistical justification).
How do we associate a temperature with a quantum state? For any quantum state with average energy $E$, we can define a temperature from the energy by solving
$$E = \langle H \rangle_\beta$$
Note that this answers your question regarding the discreteness of energy levels - we can always consider the average energy of a state, which is continuous.
Now, imagine that your quantum mechanical system is very large. It may turn out to be the case that the expectation values of operators restricted to a small region of the system look thermal - in other words, they take values close to $\langle \mathcal{O} \rangle_\beta$. If this is true, then we say that our system has thermalized, and it becomes useful to talk about thermal expectation values. It's easy to come up with states that don't satisfy this, but it turns out (rather non-trivially) that many states tend to become thermal if you evolve them in time long enough.