The United States was not willing to go to war with Japan. Commodore Perry had not been authorized to start a war nor to explicitly threaten one. His orders from President Fillmore stated that he should "refrain from every act that could possibly disturb the tranquility" of Japan. (Obviously not honoured in spirit, but it was an explicit instruction against war.) Perry did make threats in his dealings with the Japanese, mostly implicit ones, through display and preparation of his guns. He communicated the idea that he was quite willing and ready to bombard Edo. And the shogunate at last backed down and gave him his way.
However, the United States had never planned a war. Perry was at the most ready to use his guns to fight back an attack and to secure his landing and provisioning. There was no appetite to undertake a full invasion and colonization of Japan. Shelling coastal cities and fortifications, then dismantling the latter, were about the most any foreign navy could do - and in the 1860s, the British and other Western navies do take this sort of action against two Japanese domains: Satsuma and Choshu. But Perry was basically there to see how far he could push the envelope without actually having to fight.
As to why the U.S. was interested in Japan, the following is modified from previous answers I've written on this sub:
The Western powers were not primarily interested in Japan as a trading partner, though there were profits to be made in that trade. The most immediate economic motivation for opening Japan was the American need for "coaling stations" and safe harbour in the East Asian Pacific. The European colonial powers had their own bases in Asia, and Japan was out beyond their ordinary trade routes. For the Americans, however, Japan was "on the way" to China. Since they were already trading with China, and whaling in the North Pacific near Japan, stopping in Japan to refuel and re-water was an attractive proposition.
W.G. Beasley writes that the British in the late 1840s/early 50s recognized that the United States was bound to open up Japan soon, so it was not worth their time or expense to seriously try themselves. Once Japan was open to trade, all parties including Britain could sidle in and see what profit and influence there was to make.
There were some Americans who fancied that Japan was fabulously rich in silver. Four hundred years earlier, in fact, Japan had supplied 30% of the world's silver, exporting mostly to China. But back in the sixteenth century, the Japanese silver mines were already drying up, while at the same time, silver was discovered in the New World. The incredibly rich Potosi mine in Bolivia became the source of silver in the world, and only small amounts of silver continued to be mined in Japan for internal use. Silver-hunters that came to Japan after trade had been fully opened were doomed to disapointment.
One non-economic reason for opening up a relationship with Japan was the treatment of foreign sailors who were shipwrecked in Japan. Although Japanese edicts had at one time said foreign sailors would be executed, in actual practice, shipwrecked sailors by this period would be held in Nagasaki until they could be shipped out via the East India Company's vessels. However, these encounters did not all go so smoothly. In the late 1840s, two separate incidents whipped up American public fury against Japan, laying a foundation for Commodore Perry’s expedition.
In 1846, seven shipwrecked sailors from the American whaler Lawrence landed their launch on Kuril Islands. Local Ainu people conveyed them to Japanese authorities, and the seven were transported to Nagasaki. In their accounts of the experience, the Americans emphasized the harsh treatment and threats of their captors. While in Nagasaki, one of the sailors attempted to escape, and was killed by the Japanese guards. “Inhumanely murdered” according to the second mate, Howe, although the carpenter Wells’ story is a bit more nuanced: the man died of a head wound incurred while trying to escape. After seventeen months captivity, during which officials in Edo took a very long time to reply to Nagasaki’s requests for orders, the surviving Americans were shipped out on East India Company ship. The American whalers arrived home in the United States with a story to tell the newspapers which provoked outrage against Japan.
In 1848, seven sailors deserted the whaler Lagoda, on account of cruel treatment from its captain. They landed in Hokkaido, where they were imprisoned while officials waited for a ship to remove them. Some of the sailors twice attempted to escape from prison, and were subsequently beaten and held in cages. After being transported to Nagasaki, the Americans were placed in a less confined prison, and informed they would be transported out by Dutch ship, but the official permission for their release was somehow delayed. Despairing for their release, the Americans began another series of escapes, one even getting out of the city and roaming around the surrounding hills. To the Nagasaki magistrate this looked like attempted espionage. The magistrate finally confined the men to cages in the ordinary Nagasaki prison. One of the men hung himself, another died from exposure. The Americans became convinced the Japanese doctor was trying to poison them. At last, five months after they’d first came to Nagasaki, they were released to an American naval vessel which had come to demand their release. The Japanese treatment of prisoners could be harsh under any circumstances, but there were definitely some huge cultural/language misunderstandings in the Lawrence and Lagoda cases, which led to the deaths of three Americans.
If you’re interested, you can read a full detailed account of the American incidents in this open-access B.A. thesis: Diplomacy Far Removed: A Reinterpretation of the U.S. Decision to Open Diplomatic Relations with Japan by Bruce Makoto Arnold.
Once trade with Japan began, coal for steamers was one of the most important products. However, the big surprise Japanese money-maker was silk. In 1860, only a few years after trade had began, there was a silk worm blight in Europe that destroyed the French and Itlalian silk industries. Japanese and Chinese silk moved into the void in the market. In Japan, silk farmers and merchants were some of the first people to see benefits from this new relationship with the global economy.
Into the Meiji era, silk was still the biggest export. Conrad Totman describes Meiji exports as follows
The predominant exports were tea, silk thread, marine products, rice, coal, copper, and miscellaneous handicraft goods such as ceramics. Of these exports, silk thread was the most important, its volume roughly quadrupling between 1868 and the early 1890s, by then constituting 42 percent of total exports. (p. 314, A History of Japan)
Last but not least, the Western powers were not motivated by Japan's gold resources, but they did in fact force Japan into a situation where Western traders depleted Japan of its gold. Traditionally, the Japanese exchange rate between gold and silver was 1:5. The worldwide exchange rate was about 1:15. (To make things even more unequal, the Japanese "silver" coinage was not pure silver.)
Western diplomats forced Japan by trade agreement to accept Western silver at par (by weight) with Japanese "silver" coins. Western traders realized that if they exchanged silver for Japanese gold, then sold the gold abroad, they could make 200% profits. In 1860, these merchants basically looted Japan of 4 million or more ryos of gold, destroying the Japanese currency, and causing economic disaster and inflation.
What moment exactly are you talking about? Commodore Perry and the black ships, I presume?
The ruling power at the time was the Tokugawa regime which found itself in a state of chronic low-grade crisis (if wished more details can be added to this topic). In this situation of social discontent and fiscal crisis the unpredictable factor of foreign power put a lot of pressure on the government. First of all it has to be noted, that the Dutch were trading with Japan already in Nagasaki, leading up to what often is referred to the "opening" of Japan.
1780s - The Russians pressure Japan from the north. After being decline trade privileges the Russian slowly but increasingly conducted violent incursions in the north.
1808 - The British joined the scene.
1825 - The Japanese had a new policy. Foreign ships would be first fired at. Questions will asked later.
1837 - The American trade ship Morrison was expelled form Japanese waters under cannon fire.
1842 - The Opium War came to an end and the British forced "free trade" on China. In addition the British could impose British law on Chinese soil. This outcome was also understood as a warning in Japan and the policy of 1825 was revoked and replaced with one that allowed foreign ships landing on Japanese coast (for refueling and restocking food rations). In all of this the Japanese/bakufu tried its best not to appear weak which already consumed all they got. A display of power was out of question. It was not ruled out that one could get colonialized.
1853 - The first appearance of Commodore Matthew Perry who transmitted the easy message "Trade in peace or suffer the consequences in war.". America wanted to access Japanese waters for whaling. Whereas competing the British was also a factor for approaching Japan.
1854 - Perry returns for an answer with nine ships, three of them the often depicted steam frigates. The Japanese had no resources for a war and they had to accept the conditions imposed by the Americans. The Treaty of Kanagawa was put into effect.
1858 - The bakufu signed a treaty resembling the Opium War settlement with China. With war not being an option eight ports were opened, the tariffs on the goods was fixed in the treaty and foreign jurisdiction in these ports (namely crime by foreigners was not or very rarely punished). This was a very humiliating settlement in which Japan effectively became a subordinate to foreign governments.
In the time between the 1800s and the 1860s Japan had a rough time dealing with the foreign barbarians because the had no option for resistance. As a consequence modern Japanese nationalism could get created.
The fall of the Tokugawa rulership is crucial to understand how Japan rose to the power it was at the beginning at the 20^th century. But this would be the topic for another thread.
tl;dr: Japan was suffering internal conflicts and had not enough strength to oppose the increasing pressure of foreign countries. The pressure led to Japan reducing its resistance increasingly until they were imposed with similar treaties as the Chinese were after loosing the Opium War. Japan had no option for a war and its weakness got exploited in the consequence.
Source: Gordon, Andrew. A Modern History of Japan. From Tokugawa Times to the Present. New York: Oxford University Press. 2014. p. 47-63.