javascript – Discord Bot | discord.js | TypeError: Cannot read property ‘length’ of undefined

I am making a Discord bot, and I am using CodeLyon’s Permissions V2 video as a reference.

The error is in my message.js file. Here is my message.js:

//create cooldowns map
const cooldowns = new Map();
module.exports = (Discord, client, message) => {
    const prefix = process.env.PREFIX;
    if (!message.content.startsWith(prefix) || return;

    const args = message.content.slice(prefix.length).split(/ +/)
    const cmd = args.shift().toLowerCase();

    const command = client.commands.get(cmd) || client.commands.find(a => a.aliases && a.aliases.includes(cmd));

    const validPermissions = (
        let invalidPerms = ()
        for(const perm of command.permissions){
                return console.log(`Invalid Permissions ${perm}`);
        if (invalidPerms.length){
          return`Missing Permissions: `${invalidPerms}``);

    //If cooldowns map doesn't have a key then create one.
            cooldowns.set(, new Discord.Collection());
    } catch (err) {
        return message.reply("my commands are limited. I can't find that command!");

    const current_time =;
    const time_stamps = cooldowns.get(;
    const cooldown_amount = (command.cooldown) * 1000;

    //If time_stamps has a key with the author's id then check the expiration time to send a message to a user.
        const expiration_time = time_stamps.get( + cooldown_amount;

        if(current_time < expiration_time){
            const time_left = (expiration_time - current_time) / 1000;

            return message.reply(`Please wait ${time_left.toFixed(1)} more seconds before using ${}`);

    //If the author's id is not in time_stamps then add them with the current time.
    time_stamps.set(, current_time);
    //Delete the user's id once the cooldown is over.
    setTimeout(() => time_stamps.delete(, cooldown_amount);

        command.execute(client, message, cmd, args, Discord);
    } catch (err){
        message.reply("There was an error trying to execute this command!");


I have added some “permission code” in my message.js, but it says that the length of command.permissions.length is not valid.

Do I need to change or update any packages? Please tell me in the comments if I need to clarify anything.