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?
CodePudding user response:
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);
}
CodePudding user response:
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"
]
})