1st, your use of the word "dharma" is incorrect. "Dharma" is not something exclusive to Buddhism. Most or all Indian religions use the word "dharma".
"Dharma" means "bearer/supporter" and refers to any doctrine or thing that purports to support or maintain social order (such as the dharmas of social duties & morality) or to maintain the well-being or peace of the mind (such as beliefs in god, gods, reincarnation, rebirth, meditation, wisdom, Nirvana, etc).
It follows a monotheistic religion can also be 'dharmic'.
The Dhamma of the Buddha is merely one many Indian dharmas. The Dhamma of the Buddha is of two types, namely:
dhamma for 'common people' (most called 'puthujjana') about social obligations (DN 31), morality (AN 10.176), kamma & 'rebirth'; and
Dhamma connected to Emptiness & Nibbana for those individuals (called 'sāvaka') with enlightenment potential.
The two types of dhamma is explained in MN 117 in the teaching of two sorts of right view.
For example, on this forum, i explain the 2nd type of Dhamma and my adversaries preach the 1st type of dharma.
Prior to the Buddha, the predominant organised religion in India was called Brahmanism. The scriptures of Brahmanism, called the Vedas, use the word "deva" ("god/deity") to refer to various powers & potentialities, including the devas of earth, wind, fire & water. Refer to Wiki, here. Therefore, the types of "devas" or "gods" are numerous; some gods appearing to be conscious godly beings and other gods appearing to be merely (unconscious material) natural forces. For example, even the Buddhist scripture have written in them: " Are the moon and sun in this world or the other world? Are they gods or humans? They are in the other world, Master Kassapa, and they are gods, not humans.” (DN 23)
The oldest Buddhist ('Pali') scriptures often refer to various gods. Most of these appear to be from the Vedas of Brahmanism however possibly some are not.
In conclusion, it appears gods have at least three roles within early Buddhism:
A probable type of religious propaganda showing the Buddha & his Enlightened Disciples are superior to the Brahmin gods, such as when the Brahma Sahampati requested the Buddha to teach his Dhamma to the world (MN 26) or when Sakka, the Ruler of the Gods, became a disciple of the Buddha; as in MN 37 & DN 16. There are many scriptures like this, including the ridiculous MN 49 & DN 11.
Used in moral teachings for ordinary (primitive superstitious) people where such common people aspire or crave to be reborn as one of these gods (refer to MN 120 for example). Since a Buddha understands most people cannot attain enlightenment, it is possible a Buddha may use what is in other religions to guide people to practise morality so these people do not engage in harming themselves & others with immoral actions.
To explain the actual reality of the world, such as to explain the various powers & principalities in this world, namely, benevolent political rulers, cruel political rulers, compassionate beings, beings with special powers, etc. For example, refer to SN 11.5 about different kinds of rulers. For example, Iti 106 refers to the parents of children as "gods".