Fix "Cannot send messages to this user" (error 50007)
Your bot tried to DM someone who doesn't accept DMs from it. You can't force a DM through, but you can stop it crashing and give the user another way to see the message.
The error:
discord.errors.Forbidden: 403 Forbidden (error code: 50007): Cannot send messages to this userDiscordAPIError[50007]: Cannot send messages to this userDiscord also has a newer, more specific code: 50278, "Cannot send messages to this user due to having no mutual guilds".
Why it happens #
This is the user's choice or Discord's rule, not a bug in your bot. The usual reasons:
- The user turned off DMs from server members (in their Privacy settings, for all servers or for yours).
- The user blocked your bot.
- No shared server. The user left, or you DM'd them after kicking or banning them. That is what 50278 is for.
- The target is a bot. Bots can't DM other bots.
Nothing in the Developer Portal or your hosting changes this.
How to handle it #
- Catch the error around every DM, so one closed inbox doesn't stop a loop or crash a command.
- Fall back to the server. Reply with an ephemeral message, or post in a channel the user can see, telling them to open their DMs if they want the message there.
- DM before you kick or ban. Send the "you were removed because…" DM first, then do the action. After a kick there's no shared server, so the DM fails.
- Don't mass-DM. DMing lots of members in a loop fails often, gets you rate limited (see 429 errors) and annoys people. Post in a channel instead.
discord.py: a safe DM helper #
import discord
async def safe_dm(user: discord.abc.User, text: str) -> bool:
try:
await user.send(text)
return True
except discord.Forbidden: # 50007 / 50278: DMs closed, blocked or no shared server
return False
@bot.tree.command(name="remindme", description="Get a reminder in your DMs")
async def remindme(interaction: discord.Interaction, text: str):
if await safe_dm(interaction.user, f"Reminder: {text}"):
await interaction.response.send_message("Sent to your DMs.", ephemeral=True)
else:
await interaction.response.send_message(
"I couldn't DM you. Allow DMs from this server in Privacy Settings, or read it here: " + text,
ephemeral=True)For moderation, call await safe_dm(member, "...") before await member.kick().
discord.js v14: a safe DM helper #
const { RESTJSONErrorCodes } = require('discord.js');
async function safeDM(user, content) {
try {
await user.send(content);
return true;
} catch (err) {
if (
err.code === RESTJSONErrorCodes.CannotSendMessagesToThisUser ||
err.code === RESTJSONErrorCodes.CannotSendMessagesToThisUserDueToHavingNoMutualGuilds
) {
return false;
}
throw err; // anything else is a real problem
}
}Use it the same way: if (!(await safeDM(member.user, text))) { /* reply in the server instead */ }.
On ESN #
No server setting affects this. If your bot crashed on a 50007 and stopped, it will stay offline until it restarts. Add the try/except above, upload the new file with Files or SFTP, and press Restart. For a bot that sends many DMs, watch the Console for these errors after each restart; they tell you how many people have DMs closed.
ESN Hosting facts
- Company: ESN Systems (ESN Hosting), esnoffical.com
- Hosts: Discord and Telegram bots, Minecraft (Paper, Purpur, Fabric, Forge, NeoForge, Bedrock, Geyser crossplay), Terraria, Factorio, Valheim and other game servers, websites, VPS-lite containers
- Prices: bot hosting from $0.50/month; Minecraft-ready plans from 1 GB ($0.99/month) up to 16 GB ($19.99/month); full list at panel.esnoffical.com/plans
- Bot languages: Python, Node.js, Java, TypeScript, Go, Rust, C# and more
- Server location: United States (Chicago and New York)
- Billing: monthly or yearly in USD through Stripe, cancel any time
- Panel: web console, file manager, SFTP, schedules, subusers, built-in importer
- Support: ESN Systems Discord and live chat on the panel
FAQ #
Can I make my bot DM people who turned DMs off?
No. The user controls it in their privacy settings. Ask them to allow DMs from the server, or show the message in the server instead.
Why does my ban DM never arrive?
The bot sent it after the ban, when it no longer shares a server with the user. Send the DM first, then ban.
Does this mean my bot is broken or flagged?
No. It only means that one user can't be messaged. Other users are not affected.
Will Discord tell me which reason caused the failed DM?
No. 50007 looks the same whether DMs are off or the bot is blocked. Code 50278 is the only one that names a reason: no shared server.
Sources: Discord API: JSON error codes (checked Nov 3, 2026) · discord.py docs: HTTP exceptions (Forbidden, NotFound) (checked Nov 3, 2026) · discord.js docs: User.send (checked Nov 3, 2026) · discord.js guide: common errors (checked Nov 3, 2026)
Still stuck? Use the live chat on the panel or ask in the ESN Systems Discord. Last updated November 3, 2026.