I am a junior in programming. I know node.js and want to write my own bot for discord.
My code which is written below doesn't work. Can you help me with this?
const { Client, Intents } = require('discord.js');
const config = require('./config.json');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
client.once('ready', () => {
console.log('Ready!');
});
client.on('message', message=>{
if(!message.content.startsWith(config.prefix) || message.author.bot) return;
const args = message.content.slice(config.prefix.length).split(/ /);
const command = args.shift().toLowerCase();
if(command === 'ping'){
message.channel.send('pong!');
}
})
client.login(config.token);
CodePudding user response:
GUILDS
intent is not enough to receive messages. You will also need GUILD_MESSAGES
intent for messages:
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES
]
})
CodePudding user response:
I didn't saw your error message yet but I assume it's because of your intents, so really easy solution is:
const client = new Client({
intents: 32767
});
But you also need to have all intents enabled in your bot settings at https://discord.com/developers