TypeError: Cannot read property 'has' of undefined

const Discord = require('discord.js');

const client = new Discord.Client();
const {token, prefix} = require(./config.json);

client.once(‘ready’, () => {
console.log(‘Ready!’);
});

client.on(‘message’, message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;

const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();

if (!client.commands.has(command)) return;

try {
client.commands.get(command).execute(message, args);
} catch (error) {
console.error(error);
message.reply(‘there was an error trying to execute that command!’);
}
});

client.login(token);

I have used this exact code before on another bot but now for whatever reason it will not work and I am not sure why.

client.commands is undefined. You need to define it.

2 Likes