0

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");
        }
    }
});
life less
  • 63
  • 4
  • If you're using discord.js v13, `message.channel.type` should be `DM` (uppercase), not `dm`: https://stackoverflow.com/a/70003784/6126373 – Zsolt Meszaros Feb 28 '22 at 19:41

2 Answers2

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"]
})
Staxlinou
  • 1,351
  • 1
  • 5
  • 20
-1

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)
       }
   })
}