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’, () => {

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) {
message.reply(‘there was an error trying to execute that command!’);


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.


Seems like your code was from the discord.js guide. Like @Ghostoblivion said you will need to add in the part where the bot will look for commands

1 Like