I'm trying to make my bot reply on messages but it doesn't work. Does anybody know how to fix this?
Code:
const Discord = require('discord.js');
const client = new Discord.Client({ intents: ['GuildMessages', 'GuildMessageReactions', 'GuildMessageTyping', 'MessageContent', ''] })
const prefix = '!';
client.once('ready', () => {
console.log('MONKE BOT RISES');
});
client.on('messageCreate', message => {
message.channel.send('pong');
console.log('hoi');
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if(command === 'ping'){
message.channel.send('pong');
}
});
client.login('<token>');
You'll need to enable the MessageContent gateway intent in the Discord Developer Portal due to its priviledged nature.
Check out a good article on this in the docs.