if(command.permissions.length){
let invalidPerms = []
for(const perm of command.permissions){
if(!validPermissions.includes(perm)){
return console.log(`Invalid Permissions ${perm}`);
}
if(!message.member.hasPermission(perm)){
invalidPerms.push(perm);
break;
}
}
if (invalidPerms.length){
return message.channel.send(`Missing Permissions: \`${invalidPerms}\``);
}
}
Error: ReferenceError: command is not defined Can anyone tell me why I'm facing this issue? I reviewed my code thoroughly and it appears to be correct.
Main.js Code
const Discord = require('discord.js');
const client = new Discord.Client({intents: ["GUILDS","GUILD_MESSAGES"]});
const prefix = '-';
const fs = require('fs');
const event_handler = require('./handlers/event_handler');
client.commands = new Discord.Collection();
client.events = new Discord.Collection();
['command_handler', 'event_handler'].forEach(handler =>{
require(`./handlers/${handler}`)(client, Discord);
})
client.login('Discord Login ID');
Event Handler Code
const fs = require('fs');
module.exports = (client, Discord) =>{
const load_dir = (dirs) =>{
const event_files = fs.readdirSync(`./events/${dirs}`).filter(file => file.endsWith('.js'));
for(const file of event_files){
const event = require(`../events/${dirs}/${file}`);
const event_name = file.split('.')[0];
client.on(event_name, event.bind(null, Discord, client))
}
}
['client', 'guild'].forEach(e => load_dir(e));
}
Command Handler Code
const fs = require('fs');
module.exports = (client, Discord) =>{
const command_files = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'));
for(const file of command_files){
const command = require(`../commands/${file}`);
if(command.name){
client.commands.set(command.name, command);
} else{
continue;
}
}
}
Message Guild Code
module.exports = (Discord, client, message) =>{
const prefix = '-';
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const cmd= args.shift().toLowerCase();
const command = client.commands.get(cmd);
if(command) command.execute(client, message, args, Discord);
}
^This includes the command permissions
Added additional sections of my code. Can anyone identify the issue? I have double-checked everything, and it seems to be correct. Please take a look, but I believe the problem lies within the code itself, not a typo.