Video games do this all the time. There are numerous ways to make firearms comparable to other weapons.
Inaccuracy
Smooth-bore guns were known for being useless at longer ranges. In the American Revolution, solders were told not to shoot at anything more than 150 feet away because they were wasting bullets. That's where the "whites of their eyes" adage came from.
Unreliability
Before mass production became a thing, you had to go to a gunsmith if you needed to replace part of your gun. Precision machining was unknown, and sketchy metallurgy meant that your gun might not stay working for 100 shots before you needed to get it repaired. Misfires were common before we developed ammo with shells, and the need to have a person carry around raw gunpowder meant that the quality of the gunpowder wasn't guaranteed.
This is compounded if you live in a world of magic. Magic tends to be all about warping the laws of physics, and precision machines are generally incompatible with them. One tiny little warp in time-space can make a gun explode in your hand. As such, a gun owner would have to familiar with what they have to do with a gun to compensate for this.
Maybe they can't have the tight barrel tolerances, so you don't get as much pressure pushing the bullet forward. Maybe you have to re-align the mechanisms between each shot. Maybe a gun requires a magic compensation device that takes a bit of skill to keep working. The entire effort might make using a gun similar to using a 3d printer last decade. More trouble than it's worth unless you're really into it.
Low power
We think of bullets as things that'll punch through almost any armor. This isn't necessarily the case. Variations in how physics work in your world might result in armor that can resist bullets, or bullets that don't hit as hard. An arrow in our world has roughly the same energy as a .22 pistol bullet. If your people are heroically strong, however, or your bows are magically enhanced, then maybe they can get more energy into a bow shot than you can safely pack into a pistol.
Noise, smell, and smoke
These are things that we never notice while playing a game, but they're significant in the real world. In the Napoleonic wars, rifles had roughly the same lethality as longbows because they filled the air with smoke. Use of guns indoors on a regular basis will result in hearing loss, and you can't do it without attracting attention.
They're rude
Have you ever had a teammate jump your case because you're doing something that they don't see the benefit of? This might be especially true if it's something that could alert the enemy, ruin your team's hearing, and is just plain stinky.