简体   繁体   English

我没有在 discord.js npmjs 插件上获取 Dms console.log

[英]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. "messageCreate"事件中的console.log()在发送 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?我的目标是在收到 DM 时记录消息,我该怎么做?

With discord.js v13 you need to enable the partial CHANNEL , so your Client must be使用 discord.js v13 您需要启用部分CHANNEL ,因此您的 Client 必须是

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.您应该将console.log function 放在代码的“真实”部分。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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