Home > Blockchain >  Collection is not a fuction Discord.js
Collection is not a fuction Discord.js

Time:10-10

I tried to get my bot to fetch other Javascript files but it says that Collection is not a function

client.command = Client.Collection();

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);
}
    } else if (command === 'ping'){
        client.command.get('ping').execute(message,args);
    }

The code is bigger but I removed it so it doesn't take up so much space.

CodePudding user response:

Collection is a class which should be invoked once required from the library

const { Collection } = require('discord.js');

client.commands = new Collection();
  • Related