简体   繁体   中英

Is it possible to make a command handler case-insensitive?

I have this command handler:

bot.on("ready", () => {
    //Command Handler

    fs.readdir("./commands", (err, files) => {
        if (err) return console.log(err);
        let jsfile = files.filter((f) => f.split(".").pop() == "js");

        if (jsfile.length == 0) {
            return console.log("Could Not Find Any Commands!");
        }

        jsfile.forEach((f) => {
            let props = require(`./commands/${f}`);
            bot.commands.set(props.help.name, props);
        });
    });
});

I want to make it case insensitive, so commands would be easier to type, but I have no clue how.

Yes. Just use var input = original.toLowerCase(); to make your code lowercase.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM