Good evening,
I would like to get some help with my discord bot. I am trying to make my discord bot answer direct messages, but it does not react. I develop this bot using javaScript and Discord.js library. My code looks like this:
export const client = new Discord.Client({intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageReactions,
GatewayIntentBits.DirectMessageTyping,
]});
await client.login(process.env.BOT_TOKEN);
client.on( "messageCreate", async (message) => {
console.log("message created...");
}
I have added intents to see direct messages with the bot and I do not understand why the "messageCreate" event only works when the message is sent in the guild (server), but sending dm to the bot does not trigger this event. When I use commands in the channels of my server, it works well and I get the log in my console (I run my bot locally for testing). I have already done some commands like ban/unban and creating embeds with gif files and it all works. Also I have tried to use conditions like this
if(message.channel.type === 'dm'){
console.log("dm received")
}
This also does not work for me.
The reason why I want to make my bot answer to DMs is I want to develop a game where one person make up a word and the other tries to guess it. So I want to be able to save the word sent to a Bot's DM in the Database. Also I would like to make my bot create secret messages in the servers channel, which only can be read by certain persons. This message can be send to a Bot's DM and then the bot would create an Embed with a button to open the message.
Would be nice if someone could help me
Thank you!