In this paper, we propose a new generalized Gerber–Shiu discounted penalty function for a compound Poisson risk model, which can be used to study the moments of the ruin time. First, by taking derivatives with respect to the original Gerber–Shiu discounted penalty function, we construct a relation between the original Gerber–Shiu discounted penalty function and our new generalized Gerber–Shiu discounted penalty function. Next, we use Laplace transform to derive a defective renewal equation for the generalized Gerber–Shiu discounted penalty function, and give a recursive method for solving the equation. Finally, when the claim amounts obey the exponential distribution, we give some explicit expressions for the generalized Gerber–Shiu discounted penalty function. Numerical illustrations are also given to study the effect of the parameters on the generalized Gerber–Shiu discounted penalty function.