There are several number of cloud types, but I only know that cumulonimbus clouds discharge electricity, which in turn produces thunder and lightning. Is this type of cloud (cumulonimbus) the only cloud that can produce an electrical discharge or are there other clouds that can produce an electrical discharge?
Why are cumulus the only basic cloud type to favor lightning?
Because the speed of rising in the updraft is fundamental to lightning formation, as shown by this example plot from Total lightning activity as an indicator of updraft characteristics by Deierling and Petersen:
The faster the air rises, the more lightning in makes. Only rapid updrafts can separate charges fast enough to overcome dissipation and build up the hundreds of millions of Volts (related ESE question) needed for lightning. Out of the three standard cloud categories, only cumulus involves significant vertical motion.
Other cloud types?
First off, nearby clouds of other types can mask the cumulus structure responsible for the lightning. Very commonly in strong storm environments, the broad widespread rising motion, especially near the warm front, can cause a thick low-level stratus deck to form. And sometimes, in situations where dynamic forcing is dominant (such as with upper-level storm systems), or where storms move into a new environments (such as lake effect snow storms), fog can be thick, such that basically nothing can be seen! So in those situations, its hard to truly attribute the lightning to the cumulonimbus, despite that being the cause.
Plus, full storm cells often develop fairly complex structures:
Due to their shape and motions, some parts of storms might reasonably be categorized as stratus or altostratus, though they stem from a larger (past or present) cumulonimbus structure. These stratus-like components include arcus, incus, and velum. And mammatus clouds that can occur as part of strong storms are actually a unique example of clouds with sinking air. Even though air in these regions isn't rising much, leftover charge from nearby (or past) updrafts can still bring about lightning. Anvil crawlers are a common lightning seen in the fairly flat upper regions of storms.
Also, while more precise cloud classifications do now set the stages of growing thunderstorms clouds into the cumulonimbus genus, the nimbus prefix classically meant precipitating (raining/hailing/snowing). Precipitation reaching the ground is not an absolute requirement for a storm cloud to produce lightning. So in a loose sense, a cloud doesn't truly have to be a cumulonimbus, at least historically.
And of course, as it can do with just about any non-insulating material, lightning can pass through inactive clouds on the journey to the ground.
But while these situations may technically satisfy your search for lightning in other clouds types, you're fundamentally right, standard lightning generally derives from cumuloform cloud origins.
I would like to extend the answer by Jeopardy Tempest and provide an alternate view of other clouds that can discharge lightning and this answer will focus more on the observational view of lightning.
The most recent review on this subject can be found in this excellent book Lightning Physics And Effects by Vladimir Rakov and Martin Uman.
In general cloud bases usually have negative charge and when you have cloud to ground discharge from the base of the cloud that is called as negative lightning and when the discharge happens from the top of the cloud (which is positively charged) that is called positive lightning. There exists an electrical dipole between the top and base of the cloud.
I am going to describe three other cases where electrical discharge and lightning have been observed apart from the cumulonimbus case
1) Stratiform precipitation from mesoscale convective complexes(MCC) Electric field measurements above mesoscale convective systems From this paper the authors report two luminous features above MCCs namely red sprites and blue jets. Sprites usually occur above the stratiform cloud that trail the convective line in MCCs. Their measurements are basically electric field magnitudes and they conclude that discontinuities in the electric field above MCCs were caused by positive cloud-to-ground lightning flashes.These positive ground flashes were detected by the National Lightning Detection Network within 1 s of the electric field discontinuity seen above the cloud with the balloon-borne electric field meter.
Voltages inside and just above thunderstorms This following study concludes that lightning contributions from mesoscale convective complexes(MCS) stratiform clouds and thunderstorm anvils does contribute to the overall global electrical circuit and the average cloud top voltage was +32 million volts above two MCS stratiform clouds and above a thunderstorm anvil.
2)Stratus, Stratocumulus and Nimbostratus - Electricity of Clouds by Imyanitov et al. Imyanitov's pioneering work in the early 1970s in Russia done with aircraft reveal that charge density of Stratus, Stratocumulus and Nimbostratus are comparable to those of thunderclouds. Pilots have reported damage by lightning in non thunderstorm clouds such as nimbostratus and altostratus.
3) Winter lightning - Has lightning been observed during winter storms ? It would seem somewhat contrary to the conventional view is that lightning is a phenomenon associated with the season of summer. However in Japan several cases of winter lightning have been studied using radar echoes as shown in this reference - A Study of Radar Echoes and their Relation to Lightning Discharges of Thunderclouds in the Hokuriku District Part II: Observation and Analysis of "Single-Flash" Thunderclouds in Midwinter and these are the conclusions
- For the generation of lightning discharges, the cloud top has to develop high enough in the troposphere;specifically, the 30 dBZ echo of the clouds has to develop higher than the -20℃ temperature level.
- For the generation of lightning discharges, there has to exist a sufficient altitude of the -10℃ temperature level from the ground where precipitation particles are formed and electrified; specifically, it should be at least 1.4km.
- For the generation of lightning discharges, the clouds have to involve rapid development of graupel precipitation; specifically, they have to involve formation and vertical movement of 40-to-50 dBZ echo cells
When the altitude of the -10 C temperature level is below 1.4 kms no lightning activity is observed and the above reference also mentions that a Japanese aircraft that took off on 29th January 1991(during boreal winter) was stuck by lightning as it "invaded" convective clouds. However these are weak flashes and are known as "Single Flash" thunderstorms.
4) Can a tropical hurricane discharge lightning flashes ? It has certainly been observed in Hurricane Andrew Cloud to ground lightning in Hurricane Andrew and the authors report that positive eye wall flashes have been reported from the cloud tops in addition to negative eye wall flashes from the highest eye wall cloud tops.