Issue with dm message event using messageCreate.

client.on('messageCreate', async (message) => {
console.log('Received message:', message); // Log the entire message object

if (message.channel.type === ChannelType.DM) {
console.log(`DM from ${message.author.tag}: ${message.content}`);
try {
await message.reply("Hello there! 👋");
} catch (error) {
console.error('Error replying to DM:', error);
}
} else if (message.channel.type === ChannelType.GUILD_TEXT) {
console.log('Received a message in a guild text channel');
}
console.log(`Channel type: ${message.channel.type}`);
});
client.on('messageCreate', async (message) => {
console.log('Received message:', message); // Log the entire message object

if (message.channel.type === ChannelType.DM) {
console.log(`DM from ${message.author.tag}: ${message.content}`);
try {
await message.reply("Hello there! 👋");
} catch (error) {
console.error('Error replying to DM:', error);
}
} else if (message.channel.type === ChannelType.GUILD_TEXT) {
console.log('Received a message in a guild text channel');
}
console.log(`Channel type: ${message.channel.type}`);
});
I want to log dms but whenever a dm is sent to my bot i get nothing no console log etc. But it works just fine when a msg is sent in a guild.
9 Replies
d.js toolkit
d.js toolkit•2w ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - ✅ Marked as resolved by OP
d.js docs
d.js docs•2w ago
To receive direct message events on "messageCreate" with your bot, you will need: - The DirectMessages gateway intent - The Channel partial setting
treble/luna
treble/luna•2w ago
also that second channel type is wrong its PascalCase you didnt ask an ai to write that did you
Panda
PandaOP•2w ago
I did for this after I got frustrated of it not working and wanted to see if I could get any insight and I forgot to make a copy of my original so here I am :sad:
treble/luna
treble/luna•2w ago
ai is just gonna make it worse
d.js docs
d.js docs•2w ago
:dtypes: v10: ChannelType - GuildText read more
Panda
PandaOP•2w ago
I dont use it often only when im really stuck but then I remembered this server exists :md_ohmy:
treble/luna
treble/luna•2w ago
this is your issue though either forgot the partial or both
Panda
PandaOP•2w ago
I have intents so it is partials :E_think:

Did you find this page helpful?