-3

i would like to add aliases in my code but i dont know how to embed it. You have an idea ?

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);
    });
  });
LachlanDev
  • 355
  • 2
  • 14
  • Hi and welcome. I think you're going to need to be a bit more specific and give us some additional details on what you expect to achieve. – Ken Bonny Jan 27 '21 at 07:57
  • Does this answer your question? [Discord bot: Command Handler alias for command name](https://stackoverflow.com/questions/63139763/discord-bot-command-handler-alias-for-command-name) – Ken Bonny Jan 27 '21 at 07:58

1 Answers1

0

You can setup your command files to have aliases in them like this:

module.exports = {
    name: 'command',
    description: 'description',
    aliases: ['cmd', 'another alias'],
    execute(message, args) {
        // ...
    }
};

Then if you wanted to find a command by it's alias you can use:

client.commands.find(cmd => cmd.aliases.includes("an alias"));

You can find more about using aliases in this guide

Pentium1080Ti
  • 1,040
  • 1
  • 7
  • 16