-2
module.exports.config = {
    name: "av",
    aliases: ["icon", "pfp"]
};

index main file:

bot.commands = new Discord.Collection();
bot.aliases = new Discord.Collection();
fs.readdir("./commands/general", (err, files) => {

    if (err) console.log(err);

    let jsfile = files.filter(f => f.split(".").pop() === "js");
    if (jsfile.length <= 0) {
        console.log("Couldn't find the general commands.");
        return;
    }
    jsfile.forEach((f, i) => {
        let props = require(`./commands/general/${f}`);
        console.log(`${f} loaded!`);
        bot.commands.set(props.config.name, props);
        bot.aliases.set(props.config.name);
    });
});

On message

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

note: all the commands work very well but tried fixing aliases many times using different ways.

double-beep
  • 5,031
  • 17
  • 33
  • 41
dali
  • 5
  • 1
  • 3
  • 1
    could you clarify what help you need? You never asked a question, just posted some code and hoped people would understand what you mean – Joe Moore Apr 21 '20 at 13:21
  • @Proto idk how to use aliases, it doesnt work bruh everything works well without even errors besides the aliases they dont work – dali Apr 22 '20 at 00:21
  • 1
    You still havent specified what youre question is – Joe Moore Apr 22 '20 at 22:37
  • bruuuuuh i literally said i want to use aliases do you even know what are aliases ? how isnt that clear enough. the code im using doesnt let me use aliases like "icon or pfp" commands instead of the main cmd "av" duh – dali Apr 25 '20 at 21:59
  • bruh lol i said "i need to use aliases" – dali Apr 27 '20 at 13:56
  • for commands, like .icon and .pfp instead of .avatar – dali Apr 27 '20 at 13:57

1 Answers1

0

You have two collections, you arent setting any value for bot.aliases either, and the key is still props.config.name, you could stick with two collections but there is no practical use and it just makes the code worse

so get rid of the the aliases collection and bot.aliases.set(props.config.name)

Next, whats the actual function property? useless for it to be on the config object if you have it there currently.

So assuming your layout is now

module.exports.run = () => { /* function, doesnt have to be run */ }
module.exports.config = {
};

the code in the main file

jsfile.forEach(f => {
    let props = require(`./commands/general/${f}`);
    console.log(`${f} loaded!`);
    bot.commands.set(props.config.name, { 
        run: props.run,
        ...props.config
    });
});

the code on the check

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

//to actually run it you would need to do
command.run();