I am not making a command, i just want to send a message whenever a user dm's the bot. Any message. here's the code i wrote but it is specific for a command-
client.on("messageCreate", (message) => {
if (message.content === "hi") {
message.member.send("Hello")
}
})
To execute a piece of code when a user DMs a bot, all you have to do is add the DIRECT_MESSAGES intent to your client. Then you can modify your current code to check if the message sent was in a DM and then execute a piece of code:
client.on("messageCreate", (message) => {
if (message.channel.type === 'DM') {
// Execute something
}
})