these are called "ghost guns". they were used in the killing of united healthcare ceo brian thompson recently by (allegedly) luigi mangione. in some places, especially most of the us, they are completely legal to make and own. with a bit of technical know-how, it can be done. if you choose to go this way, do a LOT of research first. there is plenty of information online, including open source cad models, instructions, etc. there are even entire youtube channels like print shoot repeat dedicated to making and showcasing 3d printed firearms.
that being said, do be warned that it will get expensive fast. don't cheap out too much on the printer or the filament. pla+ is the standard filament, usually from esun or polymaker. carbon fiber nylon filaments like pa6-cf are also used as they are stronger and stiffer, but they require a much more expensive printer and there are a lot of way to fuck it up so i wouldn't recommend them to someone without a lot of 3d printing experience. plus, pla+ only really fails over long firearm lifespans and loads of repeated use, neither of which are happening here. for a handful of shots, pla+ will be totally fine. 3d printed parts are a lot stronger than people give them credit for.
as for the printer, i highly recommend the bambu lab a1 mini if you can afford it, around 200 usd when it's on sale. super user friendly and it just works well out of the box. if you can't get your hands on one, do some research and get the highest quality one you can affore. seriously, don't skimp out on this and just buy the cheapest one off of amazon.
though most of the gun can be 3d printed, a lot of it still has to be purchased, like springs, bearings, and of course ammo. if you live somewhere where ghost guns are illegal, this may be difficult depending on how well-enforced it is.
as for your comment about a shotgun, a simple pistol is going to be orders of magnitude easier and still effective. if you don't have any prior experience 3d printing, i wouldn't even try building your own shotgun.
once you've settled on a pistol design and purchased everything, run a few test prints to make sure that your printer is printing parts correctly and that your print settings are all good. and finally, once youve printed and bought everything, give it some testing, and you should be good to go.