I'm getting an error and i don't dont how to solve it and i don't know where i do a mistake. I'm using discord.js v12 I'm making this bot on the website named with "Glitch"
I can't solve it bt myself after 2 hours. I looked lots of posts but none of them solved my problem
my error:
/app/main.js:25
client.commands.set(command.name, command);
^
TypeError: Cannot read property 'set' of undefined
at Object.<anonymous> (/app/main.js:25:21)
at Module._compile (internal/modules/cjs/loader.js:759:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)
at Module.load (internal/modules/cjs/loader.js:628:32)
at Function.Module._load (internal/modules/cjs/loader.js:555:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:826:10)
at internal/main/run_main_module.js:17:11
my code:
const discord = require("discord.js");
const client = new discord.Client();
const config = require("./config.json");
const fs = require('fs');
const prefix = client.PREFIX;
client.on("warn", info => console.log(info));
client.on("error", console.error)
client.on("ready", () => {
console.log(`Loggined in as ${client.user.tag}!`)
client.user.setActivity(`${client.activity}`, { type: `${client.activityType}`})
})
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of commandFiles){
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
};
client.on('message', message =>{
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'){
client.commands.get('ping').execute(message, args);
};
})
client.commands = new discord.Collection()
client.PREFIX = config.PREFIX
client.activity = config.ACTIVITY
client.activityType = config.ACTIVITYTYPE
client.login(process.env.TOKEN)