Click here to Skip to main content
15,513,354 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to make my bot command space insensitive. Everytime I do something like "go rps" the unknown command thing still outputs even though go rps is a command. For command like "view" the unknown command thing works. I have my code linked below! I figured out how to make it case insensitive but not space insensitive. This code I found online a few hours ago. The only thing that worked. Can someone please help me get the spacing ones, like "go rps" should be working. Anyways, please help. Thanks.

What I have tried:

client.on('message', (message) => {
    if(!message.content.startsWith(PREFIX)) return;
    let validCommands = ["go rps", "go mountains", "go hills", "go cannons", "go left", "go east", "go west", "view", "holler"];
    // Added the .toLowerCase() function vvv to make everything work both ways 
    const args = message.content.toLowerCase().substring(PREFIX.length).slice().split(/ /);;
    const command = args.shift();
    const isValid = validCommands.includes(command); 
    const unknowncommand = new Discord.MessageEmbed()
    .setDescription('You\'ve entered an unknown command. \nUse **!help** to see all available commands.')   
        if( return;
        return, console.log(`[SCOTT] ${} entered an unknown command in "${}".`);
Updated 28-Jul-20 22:56pm

1 solution

Why not split the command string first and check if the first word is 'go'. If it is then check the second word against a separate list of 'go' commands. So you would have two command lists:
let validCommands = ["go , "view", "holler"];

let goCommands = ["rps", "mountains", "hills", "cannons", "left", "east", "west" ];
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900