Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

250
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!