If strangers in shared servers keep appearing in your Discord inbox, you can limit who can send you direct messages without leaving the communities you enjoy. Discord keeps these controls in Content & Social, with global and per-server options.
What turning off server DMs does
By default, people who share a server with you may be able to send a direct message. Turning off Direct messages stops non-friends in the selected server or servers from starting new DMs with you. It does not remove your existing conversations or stop friends from messaging you.
Stop server members from DMing you on desktop or browser
Open Content & Social
Select the cogwheel next to your username to open User Settings, then choose Content & Social.
Turn off Direct messages
Under Social permissions, turn off Direct messages. Discord will ask whether to apply the change to all existing servers. Choose that option if you want the same rule everywhere, or keep it server-specific if you only need it in a busy public community.
Stop server members from DMing you on mobile
Tap your profile icon or You Bar, open the cogwheel, then go to Content & Social. Scroll to Server Settings and turn off Direct messages. The exact wording can differ slightly by app version and region.
Use per-server settings when you need an exception
You do not have to use one rule everywhere. Discord lets you adjust social permissions for individual servers through the server selection menu in Content & Social. This is useful when you want DMs enabled in a small community but disabled in large public servers.
Use Message Requests and spam filters too
Discord may place a first DM from someone you are not friends with in Message Requests, and suspected spam can go to a separate Spam folder. In Content & Social, you can also choose whether Discord filters DMs from non-friends, filters all DMs, or does not filter them. The Spam folder itself cannot be turned off.
Block a specific person when needed
For an individual account, open the user’s profile or the member list, select the ellipsis menu, and choose Block. That is more targeted than changing a server-wide rule.
Keep useful old conversations accessible
Changing DM privacy settings affects new contact, not messages you already have. If an important older conversation disappears from your visible DM list, Friendcord can help you search the Discord data package you already requested and find old messages or contacts again.
FAQ
Can friends still DM me after I turn off server DMs?
Yes. The Direct messages control is for non-friends in shared servers.
Does turning off server DMs delete past conversations?
No. It changes who can start future direct messages; it does not delete existing chat history.
Can I allow DMs in only one server?
Yes. Use Discord’s per-server social permissions instead of applying the global choice to every server.
Source
Discord Support: Blocking & Privacy Settings
Discord Support: Safer Messaging on Discord