简体   繁体   中英

I m not getting Dms console.log on discord.js npmjs plugin

The console.log() in the "messageCreate" event is not firing when sending a DM.


const Client = new Discord.Client({
    intents: [
        "GUILDS",
        "GUILD_MESSAGES",
        "DIRECT_MESSAGES"
    ]
})

Client.on('messageCreate', (msg) => {
   msgArray = msg.content.toLowerCase().split(' ')

   if (msgArray[0] == "/botmsg"){
    Client.users.fetch(msgArray[1], false).then((user) => {
        user.send(msgArray[2]);
       });
   } else {
    console.log(msg.content);
   }
})

Client.login('token hidden')

My goal is to log the message when a DM is received, how can I do this?

With discord.js v13 you need to enable the partial CHANNEL , so your Client must be

const Client = new Discord.Client({
    intents: [
        "GUILDS",
        "GUILD_MESSAGES",
        "DIRECT_MESSAGES"
    ],
    partials: [
        "CHANNEL"
    ]
})

You should put your console.log function in the "true" part of code.

if (msgArray[0] == "/botmsg"){
    Client.users.fetch(msgArray[1], false).then((user) => {
        user.send(msgArray[2]);
    });
    console.log(msg.content);
} else {
    console.log(msg.content);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM