I know that "the CHANNEL partial must be enabled" and it is. But my bot still can't recognize DM messages.
Here is my code:
const client = new Client({intents:[...],partials:[Partials.Channel,...]});
client.on("messageCreate", (message) =>{
if (message.channel.type === 'DM') console.log('Dm recieved');
})
All the other parts of the bot work except this part.
CodePudding user response:
Please see the guide on how to handle events. My personal recommendation is to use an individual file type event handler
Example:
const { Events } = require('discord.js');
client.once(Events.messageCreate, message => {
console.log(`Message event triggered! Message: {message.content}`);
});
My recommendation (individual file type event handler):
for (const file of eventFiles) {
const event = require(`./events/${file}`);
console.log(`| ✅ ${file} loaded!`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args, commands));
} else {
client.on(event.name, (...args) => event.execute(...args, commands));
}
}
module.exports = {
name: "messageCreate",
once: false,
async execute(message) {
// Your code to handle messages
}
}
You can also try logging in the event to check if it's being triggered correctly.
If the above answers do not work, you can try this:
if (message.channel.isDMBased())