'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?
Solution 1:[1]
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);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tyler2P |
