Dm discord.js 14.14.1
how to make it so that when I write to the bot via dm, it will write it in the console or on some channel
12 Replies
- 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 stafflisten to the messageCreate event, add the DirectMessages and MessageContent intent and also the Channel partial.
To receive direct message events on
"messageCreate"
with your bot, you will need:
- The DirectMessages
gateway intent
- The Channel
partial settingclient.on('messageCreate', msg => {
if (msg.channel.type === 'dm') {
console.log(msg)
}
})
msg.channel.type === ChannelType.DM
ChannelType being imported from discord.js
thanks
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildInvites,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageReactions
],
partials: [
'CHANNEL',
]
});
Use the Partial enum, and its Channel
how should I do it?
what?
because it still doesn't work
Import Partials and use Partials.Channel
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildInvites,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageReactions
],
partials: [
Partials.Channel,
]
});
works, thank you