I’m coding a discord bot in JavaScript.
I try to make commandss that work in Direct Message but when I execute commands in Direct Message, the bot does not respond (as if it does not detect messages sent in DM). Which blocks the progress of the script.
I set the intents when the bot starts.
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.DirectMessages
]
});
I tried the “if (message.channel.type === ‘DM’)”
client.on('messageCreate', async message => {
if (message.channel.type === 'DM' && message.content === '-hi') {
try {
await message.channel.send(':white_check_mark: | You have enabled the `-hi` command in server mode.');
} catch (error) {
console.error('error :', error);
}
}
});
I also tried “if (!message.guild)”
client.on('messageCreate', async message => {
if (!message.guild && message.content === '-hi') {
try {
const user = message.author;
await user.send(':white_check_mark: | You have enabled the `-hi` command in server mode.');
} catch (error) {
console.error('error :', error);
}
}
});