I was trying to make a discord bot as a project and I’ve watched plenty tutorials but I couldn’t get it to work since it doesn’t detect messages and when it does detect is says (usernmame) said: ‘’
const Discord = require("discord.js");
const client = new Discord.Client({
intents: [
'GUILDS',
'DIRECT_MESSAGES',
'GUILD_MESSAGES'
],
partials: ['MESSAGE', 'CHANNEL']
});
client.once('ready', () => {
console.log(`Bot started as ${client.user.tag}!`);
});
client.on('messageCreate', message => {
if (message.author.bot) return;
const username = message.author.username;
const userMessage = message.content;
const channel = message.channel.name;
console.log(`${username} said: '${userMessage}' (${channel})`);
if (userMessage.toLowerCase() === 'hello') {
message.channel.send(`Hey there, ${username}!`);
}
});
const token = 'my token';
client.login(token);