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

173
Views
Only reply in dms discord.js

So I was working on this project where people will DM the BOT and run command and it replies test. But it doesn't reply.

client.on("messageCreate", async message => {
    if (message.content.startsWith(prefix)) {
        const args = message.content.slice(prefix.length).trim().split(/ +/g);

        const command = args.shift().toLowerCase();

        if (message.channel.type === 'dm') {
            message.reply("test");
        }
    }
});
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

That's because you didn't enable the intents for getting a dm message, try putting those two on your client declarations :

const client = new Discord.Client({
    intents : ['DIRECT_MESSAGES','GUILD_MESSAGES'],
    partials: ["CHANNEL","MESSAGE"]
})
about 4 years ago · Juan Pablo Isaza Report

0

here is a way:

1.Create a file named ** 'privateMessage.js'** and in the main file add:

const privateMessage = require('./privateMessage')

client.on('ready' ,() =>{
console.log('I am online')
client.user.setActivity('YouTube Music 🎧', {type:'PLAYING'})
privateMessage(client, 'ping', 'pong')

})

and in the file we just created privateMessage.js add:


module.exports=(client, triggerText, replyText)=>{
   client.on('message', message =>{
       if(message.content.toLowerCase()===triggerText.toLowerCase()){
           message.author.send(replyText)
       }
   })
}
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!