Gunfire will frighten muskrats, especially those that are hit, but it is not effective in the long term at scaring the animals away from occupied habitat. As always, never discharge a firearm without consulting local, state and federal laws and without due concern for safety considerations. Nevertheless, no conventional frightening devices are known to be effective.
Additionally, no repellents are currently registered for muskrats, and none are known to be effective, practical, and environmentally safe.
Resources: (online)