Keith Gracshel Keith Gracshel - 1 month ago 13
Javascript Question

Discord.js user.bot is not defined?

const Discord = require('discord.js');
const client = new Discord.Client();

client.on('ready', () => {
console.log('Succesfully contacted the server.');
});

client.on('message', message => {
if (!user.bot) {
message.delete()
.then(message.reply('nope.'));
}
});



client.login('Nope');


When I say something in discord chat I get the error in the console "ReferenceError: user is not defined."

Answer Source

You're getting the error ReferenceError: user is not defined. because you haven't defined user, surprisingly enough.

client.on('message', message => {
    let user = message.author;
    if (!user.bot) {
        message.delete()
           .then(message.reply('nope.'));
    }
});