ReferenceError: command is not defined [DISCORD.JS]

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:

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);


const validPermissions = [


































let invalidPerms = []

for (const perm of command.permissions) {

    if (!validPermissions.includes(perm)) {

        return console.log(`Invalid Permissions ${perm}`);


    if (!message.member.hasPermission(perm)) {





if (invalidPerms.length) {

    return`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. :slight_smile:

the variable command that you’re using is a scoped variable that you declared here:

which means that the command variable can only be used in that loop.