Home > Software engineering >  How to add more then one names to a command?
How to add more then one names to a command?

Time:04-05

If I add more then one property to "name" then it doesn't detect any.

This works:

module.exports = {
  name: "info",
  description: "Gives full details of a user.",
  async execute(...) {
    ...
  }
}

But if i try to add something like "whois" to "name":

module.exports = {
  name: ["info", "whois"],
  description: "Gives full details of a user.",
  async execute(...) {
    ...
  }
}

Then the command just stops working.

Here the code for my index.js:

const infoCommandModule = require(`./BotCommands/Info.js`);
if (msg.content.toLowerCase() === `${infoCommandModule.name}`) {
  infoCommandModule.execute(...)
}

CodePudding user response:

It's because when it's an array you can't compare it to a string. You can use Array#includes() though that checks if a given string is included in the array:

const infoCommandModule = require('./BotCommands/Info.js')

if (infoCommandModule.name.includes(msg.content.toLowerCase)) {
  infoCommandModule.execute(...)
}

Please note that you will need to use arrays for every name in your commands. If you want to accept arrays and strings too, you will need to check if name is an array. You can use Array.isArray(name) for that.

  • Related