In Don't Starve Together, the Pan Flute has a 100% chance to be found around the Glommer's Statue. In the Hamlet DLC, the Pan Flute is renewable since Mandrakes can be bought in 'The Sty' Oddities Emporium for 50 Oincs. In the Shipwrecked DLC, the Pan Flute can rarely be found when fishing with the Trawl Net, making it renewable. In the Reign of Giants DLC, the Pan Flute has a 75% chance to be found around the Glommer's Statue.
The cheat method to spawn either, enter the console by hitting and type: DebugSpawn ('carrot') DebugSpawn ('mandrake') To exit the console hit Control-L.
Carrots can be grown from seeds in farms, though. Mandrakes also have a chance to be obtained from Klaus's loot. Per the Don't Starve Wiki, neither carrots, nor mandrakes re-spawn on their own. Mandrakes are rare and if the player wishes to use Pan Flute more, they can deconstruct a Pan Flute using a Deconstruction Staff and craft it again to renew its durability. The Pan Flute also complements the Feather Hat when looking for Morsels and Feathers. The Pan Flute can be used to get an advantage over enemies, shave Beefalo, or steal Tallbird Eggs and Pengull Eggs, to cool down enraged Dragonfly and buy time against Toadstool when it is trying to summon Sporecaps. Mobs sometimes sleep all day after they have been put to sleep by the Pan Flute. If a mob that was put to sleep is attacked, all of the similar nearby mobs will wake up after a couple of seconds. Mobs will be put into a deeper sleep than usual, allowing the player to move closer to them without waking them up for example, the Tallbird. It takes 1 second to begin playing the Pan Flute after clicking it. When played, it puts all Mobs within 15 m to sleep, except for those that are incapable of sleeping. It requires 5 Cut Reeds, 1 Mandrake, and 1 Rope to craft, and a Prestihatitator to prototype.