Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

247
Vistas
How do I check if a message is a DM in Discord.js?

Currently I am using the latest version of Discord.js (v13.1.0).

I want to be able to detect if a certain message is a DM. I tried making a messageCreate event and did an if statement to check if the channel is a DM

client.on('messageCreate', message => {
   if (message.channel.type == 'DM') {
      console.log('Dm recieved!')
   }
})

This for some reason didn't work. So I have no idea what will.

Here are my intents:

[Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MESSAGE_REACTIONS, Intents.FLAGS.DIRECT_MESSAGES]

Btw, the event does work:

client.on('messageCreate', message => {
   console.log('Event')
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I had this issue earlier as well; I dug into the changes between discord.js v12 and v13 and figured out why.

As seen here on the discordjs.guide webpage dedicated to the breaking changes between the updates:

On Discord API v8 and later, DM Channels do not emit the CHANNEL_CREATE event, which means discord.js is unable to cache them automatically. In order for your bot to receive DMs, the CHANNEL partial must be enabled.

For the very important feature of handling DM messages, that notice was pretty difficult to find. It only directly mentions the CHANNEL_CREATE event, but basically what it means is that your bot is unable to receive DMs at all unless the CHANNEL partial is enabled in your client options.

Here is an example of how you would do that:

const client = new Discord.Client({ partials: ["CHANNEL"], intents: [...] });

You need to add that partials property to your Client constructor in order to receive DMs. After doing so, your code will work properly.

about 4 years ago · Juan Pablo Isaza Denunciar

0

I had the same problem the solution was modifying the client variable adding this

Thanks to Cannicide

const client = new discord.Client({ partials: ["CHANNEL"], intents: [
    discord.Intents.FLAGS.DIRECT_MESSAGES, 
    discord.Intents.FLAGS.DIRECT_MESSAGE_TYPING
]})
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda