TypeError: client.commands.set is not a function
acryllect opened this issue · 1 comments
acryllect commented
Hi. I'm getting the error "TypeError: client.commands.set is not a function" and i cannot for the life of me figure out why. My code is almost exactly the same aside from my commands.js - here's my code, maybe someone can help me.
Index.js
require('dotenv').config();
const fs = require('fs');
const Discord = require('discord.js');
const Enmap = require("nmap");
let client = new Discord.Client();
console.log('🤖 > Fortuno sta startando...');
client.login(process.env.TOKEN);
client.on('ready', readyDiscord);
function readyDiscord() {
console.log('🤖 > Ok! Fortuno è online!');
client.user.setActivity('Sohub Laib', { type: 'WATCHING'});
}
fs.readdir("./events/", (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
const event = require(`./events/${file}`);
let eventName = file.split(".")[0];
client.on(eventName, event.bind(null, client));
});
});
client.commands = new Enmap();
fs.readdir("./commands/", (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
if (!file.endsWith(".js")) return;
let props = require(`./commands/${file}`);
let commandName = file.split(".")[0];
console.log(`Attempting to load command ${commandName}`);
client.commands.set(commandName, props);
});
});
./events/message.js
const prefix = "f!"
module.exports = async(client, message) => {
if (message.author.bot) return;
if (message.content.startsWith(prefix)) {
let messageArray = message.content.split(" "),
cmd = messageArray[0],
args = messageArray.slice(1),
commandfile = client.commands.get(cmd.slice(prefix.length)) || client.aliases.get(cmd.slice(prefix.length));
if(!commandfile) return;
commandfile.run(client,message,args);
}
}
./commands/utility.js
module.exports = async function(message) {
if (message.author.bot) return;
if (!message.content.startsWith(prefix)) return;
const commandBody = message.content.slice(prefix.length);
const args = commandBody.split(' ');
const command = args.shift().toLowerCase(), found = false;
switch(command) {
// etc...
Thanks in advance if you do take the time to help me out!
acryllect commented
Issue Resolved: NPM wasn't correctly installing enmap although it was outputting a success message.