Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to add more then one names to a command?

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":

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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(...)
}

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading