So I am trying to add permissions for one of the commands that my bot is using (Retisy Bot) and I came across this error in the console:
if(command.permissions.length){
ReferenceError: command is not defined
The full code is here:
const { RSA_PKCS1_OAEP_PADDING } = require(‘constants’);
const Discord = require(‘discord.js’);
const client = new Discord.Client();
const prefix = ‘-’;
const fs = require(‘fs’);
client.command = new Discord.Collection();
const commandFiles = fs.readdirSync(’./commands/’).filter(file => file.endsWith(’.js’));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.command.set(command.name, command);
}
const validPermissions = [
"CREATE_INSTANT_INVITE",
"KICK_MEMBERS",
"BAN_MEMBERS",
"ADMINISTRATOR",
"MANAGE_CHANNELS",
"MANAGE_GUILD",
"ADD_REACTIONS",
"VIEW_AUDIT_LOG",
"PRIORITY_SPEAKER",
"STREAM",
"VIEW_CHANNEL",
"SEND_MESSAGES",
"SEND_TTS_MESSAGES",
"MANAGE_MESSAGES",
"EMBED_LINKS",
"ATTACH_FILES",
"READ_MESSAGE_HISTORY",
"MENTION_EVERYONE",
"USE_EXTERNAL_EMOJIS",
"VIEW_GUILD_INSIGHTS",
"CONNECT",
"SPEAK",
"MUTE_MEMBERS",
"DEAFEN_MEMBERS",
"MOVE_MEMBERS",
"USE_VAD",
"CHANGE_NICKNAME",
"MANAGE_NICKNAMES",
"MANAGE_ROLES",
"MANAGE_WEBHOOKS",
"MANAGE_EMOJIS",
]
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}`);
}
}
} else if (command === 'mute') {
client.command.get('mute').execute(message, args);
} else if (command == 'unmute') {
client.command.get('unmute').execute(message, args);
}
});
Can anyone tell me why I am getting this error? I thought I did everything right but I guess I could use some more insight. Any info helps and if I need to add more for better context just comment below.