Discord · 50007

Discord error 50007: Cannot send messages to this user

Your bot tried to DM somebody and Discord refused. It is not a bug in your code, and it is not something you can fix for them — but your bot has to cope with it.

← All errors

What you are seeing

discord.js

DiscordAPIError[50007]: Cannot send messages to this user

discord.py

discord.errors.Forbidden: 403 Forbidden (error code: 50007): Cannot send messages to this user

What it means

A bot can only DM someone it shares a server with, and only if that person allows it. The three causes are: their privacy settings block direct messages from server members; they have blocked the bot; or there is no server you both belong to — they left it, or the bot was removed.

Which of the three it is, Discord does not say. The error is the same either way, and none of the three is yours to fix: the person has to change a setting, unblock the bot, or be in a server with it.

Catch it per user

This error is routine for any bot that DMs people — verification codes, ticket updates, giveaway wins. If one failed DM throws out of your code, everything after it never happens: the next user in a list, or the rest of the command. Catch it where you send, tell the user in the open channel that their DMs are closed, and carry on.

discord.js

try {
    await user.send('Your verification code is 123456.');
} catch (error) {
    if (error.code === 50007) {
        await interaction.reply({ content: 'I could not DM you — check your privacy settings allow direct messages from server members.', ephemeral: true });
    } else {
        throw error;
    }
}

discord.py

try:
    await user.send("Your verification code is 123456.")
except discord.Forbidden as error:
    if error.code == 50007:
        await interaction.response.send_message("I could not DM you — check your privacy settings allow direct messages from server members.", ephemeral=True)
    else:
        raise

Do not keep trying

Retrying a DM that Discord has refused changes nothing, and a bot that DMs the same person on every command quickly becomes the nuisance that gets it blocked. Say it once, in the channel, and leave it there. If the DM carries something the user has to have — a code, a link — put it in that channel message instead, or ask them to DM the bot first, which opens the conversation from their side.

FAQ

Questions

It worked for this user yesterday.

They changed their privacy settings, blocked the bot, or left the server you shared. Any of the three gives the same error, and the fix is theirs, not yours.

Can a bot DM someone it has never seen?

No. The bot needs a shared server, and the person needs DMs from server members switched on. A user who messages the bot first can always be answered.

What if the user blocked the bot by accident?

They unblock it from their friends list or by right-clicking the bot, then message it or use a command in a shared server. There is nothing the bot can do to unblock itself.

Read next