---
title: "How to make a Discord bot send automatic DMs to members | StreetHosting"
description: "Set up your Discord bot to send automatic direct messages (DMs) to members: when they join the server, when they get a role or in reply to a command."
url: "https://streethosting.com.br/en/guides/discord-bots/discord-bot-send-automatic-dm"
type: "page"
language: "en-US"
---

Discord Bots · 3 min · Intermediate

Published on Jun 18, 2026 · Updated on Jun 18, 2026

# Discord bot sending automatic DMs: how to set it up

Automatic DMs are useful for private welcome messages, purchase confirmations and important notifications. Learn how to implement them with discord.js and handle closed DMs correctly.

By [Equipe StreetHosting](https://streethosting.com.br/en/autores#equipe-streethosting) · StreetHosting infrastructure and support team

[Automation and webhooks](https://streethosting.com.br/en/guides/topics/automation)

Summarize with:

[](https://chat.openai.com/?q=Summarize%20the%20key%20points%20of%20this%20StreetHosting%20guide%3A%20https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fdiscord-bots%2Fdiscord-bot-send-automatic-dm.%20Highlight%20the%20step-by-step%20instructions%2C%20the%20prerequisites%20and%20the%20most%20common%20mistakes. "ChatGPT") [](https://claude.ai/new?q=Summarize%20the%20key%20points%20of%20this%20StreetHosting%20guide%3A%20https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fdiscord-bots%2Fdiscord-bot-send-automatic-dm.%20Highlight%20the%20step-by-step%20instructions%2C%20the%20prerequisites%20and%20the%20most%20common%20mistakes. "Claude") [](https://www.google.com/search?udm=50&aep=11&q=Summarize%20the%20key%20points%20of%20this%20StreetHosting%20guide%3A%20https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fdiscord-bots%2Fdiscord-bot-send-automatic-dm.%20Highlight%20the%20step-by-step%20instructions%2C%20the%20prerequisites%20and%20the%20most%20common%20mistakes. "Google AI Mode") [](https://x.com/i/grok?text=Summarize%20the%20key%20points%20of%20this%20StreetHosting%20guide%3A%20https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fdiscord-bots%2Fdiscord-bot-send-automatic-dm.%20Highlight%20the%20step-by-step%20instructions%2C%20the%20prerequisites%20and%20the%20most%20common%20mistakes. "Grok") [](https://www.perplexity.ai/search/new?q=Summarize%20the%20key%20points%20of%20this%20StreetHosting%20guide%3A%20https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fdiscord-bots%2Fdiscord-bot-send-automatic-dm.%20Highlight%20the%20step-by-step%20instructions%2C%20the%20prerequisites%20and%20the%20most%20common%20mistakes. "Perplexity")

Share:

[](https://x.com/intent/tweet?text=How%20to%20make%20a%20Discord%20bot%20send%20automatic%20DMs%20to%20members&url=https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fdiscord-bots%2Fdiscord-bot-send-automatic-dm "Share on X") [](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fdiscord-bots%2Fdiscord-bot-send-automatic-dm "Share on Facebook") [](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fdiscord-bots%2Fdiscord-bot-send-automatic-dm "Share on LinkedIn") [](https://wa.me/?text=How%20to%20make%20a%20Discord%20bot%20send%20automatic%20DMs%20to%20members%20https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fdiscord-bots%2Fdiscord-bot-send-automatic-dm "Share on WhatsApp")

For agents: Copy as Markdown [.md](https://streethosting.com.br/en/guides/discord-bots/discord-bot-send-automatic-dm.md)

In this guide 5 sections

* [When to use automatic DMs](https://streethosting.com.br/en/guides/discord-bots/discord-bot-send-automatic-dm#quando-usar-dm)
* [Send a DM with discord.js](https://streethosting.com.br/en/guides/discord-bots/discord-bot-send-automatic-dm#enviar-dm-nodejs)
* [DM when someone joins the server](https://streethosting.com.br/en/guides/discord-bots/discord-bot-send-automatic-dm#dm-ao-entrar)
* [DM when someone gets a role](https://streethosting.com.br/en/guides/discord-bots/discord-bot-send-automatic-dm#dm-por-cargo)
* [Handle closed DM errors](https://streethosting.com.br/en/guides/discord-bots/discord-bot-send-automatic-dm#tratar-erros)

Quick answer

To send a DM with discord.js, use `await member.send("message")` or `await user.send("message")`. Always wrap it in `try/catch` so users with closed DMs don't crash the bot.

## When to use automatic DMs[](https://streethosting.com.br/en/guides/discord-bots/discord-bot-send-automatic-dm#quando-usar-dm)

Automatic DMs are useful in specific situations where a private message makes more sense than a public notification:

* Private welcome with detailed instructions when someone joins the server
* Confirmation of a VIP role purchase or subscription
* Punishment notice (warning, mute, temporary ban)
* Alert for an event exclusive to members of a specific group
* Result of a submitted form or application

Don't use automatic DMs for marketing or advertising without consent. Discord treats that as spam and can ban the bot. Use DMs only for information directly related to the server and the user's actions.

## Send a DM with discord.js[](https://streethosting.com.br/en/guides/discord-bots/discord-bot-send-automatic-dm#enviar-dm-nodejs)

In discord.js, you can send a DM through a _User_ object or a _GuildMember_. The method is the same in both cases:

`// Via GuildMember (inside a server) await member.send('Olá! Esta é uma DM automática.'); // Via User (outside a server context) const user = await client.users.fetch('ID_DO_USUARIO'); await user.send('Olá! Esta é uma DM automática.');`

Prefer `member.send()` whenever you're inside a server context. It's more direct and you don't have to fetch the user separately.

## DM when someone joins the server[](https://streethosting.com.br/en/guides/discord-bots/discord-bot-send-automatic-dm#dm-ao-entrar)

Combined with the `guildMemberAdd` event, send a private welcome DM at the same time as the public message in the channel:

`` client.on('guildMemberAdd', async (member) => { try { await member.send( `Bem-vindo(a) ao servidor, ${member.user.username}!\n` + 'Leia as regras em #regras antes de interagir.\n' + 'Se tiver dúvidas, abra um ticket em #suporte.' ); } catch (err) { console.log(`Não foi possível enviar DM para ${member.user.tag}: ${err.message}`); } }); ``

## DM when someone gets a role[](https://streethosting.com.br/en/guides/discord-bots/discord-bot-send-automatic-dm#dm-por-cargo)

To send a DM when a member gets a specific role, listen for the `guildMemberUpdate` event:

`const ID_CARGO_VIP = '123456789012345678'; client.on('guildMemberUpdate', async (oldMember, newMember) => { const temCargoNovo = !oldMember.roles.cache.has(ID_CARGO_VIP) && newMember.roles.cache.has(ID_CARGO_VIP); if (!temCargoNovo) return; try { await newMember.send('Parabéns! Você agora é VIP no servidor.'); } catch (err) { console.log('Erro ao enviar DM:', err.message); } });`

## Handle closed DM errors[](https://streethosting.com.br/en/guides/discord-bots/discord-bot-send-automatic-dm#tratar-erros)

Many users turn off server DMs in their Discord privacy settings. Without error handling, the bot will throw when it tries to send. Always use try/catch:

`` try { await member.send('Mensagem importante'); } catch (err) { if (err.code === 50007) { // DM turned off by the user, a silent failure is expected console.log(`DM fechada para ${member.user.tag}`); } else { // Unexpected error, log it for investigation console.error('Erro inesperado ao enviar DM:', err); } } ``

Error code **50007**means "Cannot send messages to this user". Treat it as an expected, silent failure, not as a critical bot error.

For the bot to keep sending DMs and notifications 24 hours a day, it needs to be hosted in production. See how to [host a Discord bot 24/7](https://streethosting.com.br/en/guides/discord-bots/discord-bot-hosting-24-7).

In this guide

* [When to use automatic DMs](https://streethosting.com.br/en/guides/discord-bots/discord-bot-send-automatic-dm#quando-usar-dm)
* [Send a DM with discord.js](https://streethosting.com.br/en/guides/discord-bots/discord-bot-send-automatic-dm#enviar-dm-nodejs)
* [DM when someone joins the server](https://streethosting.com.br/en/guides/discord-bots/discord-bot-send-automatic-dm#dm-ao-entrar)
* [DM when someone gets a role](https://streethosting.com.br/en/guides/discord-bots/discord-bot-send-automatic-dm#dm-por-cargo)
* [Handle closed DM errors](https://streethosting.com.br/en/guides/discord-bots/discord-bot-send-automatic-dm#tratar-erros)

## Frequently asked questions

Can the bot DM any user on Discord?

The bot can only DM users who share at least one server with it. The user can also have server DMs turned off in their Discord privacy settings, which causes an error when you try to send.

How do I know if a user has DMs turned off?

You can't check before trying. The right approach is to attempt the DM and catch the error with try/catch. Error code 50007 ('Cannot send messages to this user') means the DM is closed.

Can I mass DM every member of the server?

Technically yes, but Discord heavily restricts it. Sending many DMs quickly can get the bot banned for spam. Never mass DM without the users' explicit consent.

How do I send an embed through a DM on Discord?

The same embed syntax that works in channels works in DMs. Use user.send({ embeds: \[embed\] }) with a configured EmbedBuilder. The embed size limit applies the same way.

Next step

See bot plans

24/7 Discord bots with fast activation and support in Portuguese.

[See bot plans](https://streethosting.com.br/en/bots)

## Related guides

[Discord bots Beginner How to set up an automatic welcome message on Discord with a bot A welcome message sets the first impression of your server. See how to set it up with your own Node.js bot or with ready-made bots, and what to include to keep new members around. 3 min Read guide](https://streethosting.com.br/en/guides/discord-bots/discord-welcome-message-bot) [Discord bots Beginner How to create a Discord bot with slash commands Slash commands improve the user experience and make your bot easier to use. Here is a clear path to get started. 2 min Read guide](https://streethosting.com.br/en/guides/discord-bots/create-discord-bot-slash-commands) [Discord bots Beginner 24/7 Discord bot hosting in Brazil Discord bot hosting 24/7 combines a process manager with automatic restart, a token kept out of your code, logs and a server in Brazil for low latency to the API and your players. 6 min Read guide](https://streethosting.com.br/en/guides/discord-bots/discord-bot-hosting-24-7)

[← Back to the Guide Center](https://streethosting.com.br/en/guides)
