Optical drives wear out and/or break.

It's possibly time to replace that drive with a new one.

How easy that is going to be depends on the model of your Mac, something you didn't share with us.

Why not consider an External CD/DVD device? Take a look at Macsales.com they have a good selection of external optical devices that are much faster than your existing one, even when it worked.