So working with discordjs and was wondering if it is possible to have my bot respond to commands sent in dms with the bot is there a way to listen to DMs? Example: user DMs the bot with !test and the bot would respond in DMs with success?
Then when setting new Discord.Client() make sure to add the "CHANNEL" partial and the DIRECT_MESSAGES intent... You must also allow this intent in your developer portal else you will get an intents permissions error.
const client = new Discord.Client({
partials: ["CHANNEL"],
intents: [Discord.Intents.FLAGS.DIRECT_MESSAGES]
})
and then in the messageCreate listener this is how you listen for a DM.
if(command === "test" && message.channel.type === "DM"){
message.channel.send("Success!")
}
this is checking if the channel the message is received in is a direct messaging channel, if not it'll return, else it will respond with with "Success!"
You could do
if(message.channel.DMChannel) {
message.author.send("Success")
}
I am not sure but it should work.
if(message.channel.type == "DM"){ // if it's v12 just type change it to "dm"
// do sth
}