Search code examples
javascriptbotsdiscord.jscommando

discord.js-commando arguments on a command with different responses


I'm trying to get my bot to run different responses after a command like >open well open what? >open door and the bot would respond with opening door or something along those lines I've read the discord command documentation I'm having a bit of trouble understanding how it works I know how to do arguments without commando but id love to know how to do it with commando the best I can think of is }else{ but I don't know how to check for args then to verify any ideas? ive tried the arguments in the documentation can't seem to get a response.

run(message) {
const args = message.content.slice(prefix.length).split(' ');
const command = args.shift().toLowerCase();

    return message.say('*Your wand projects a stream of water*');

}else{
    if (command === 'aguamenti cup') {
    return message.say('*Your wand projects a stream of water into a cup*');

}else{




}
}

tried this way doesnt seem to want to work


Solution

  • Your javascript syntax is wrong or you aren't showing the whole code, }else{ where is the if statement?

    There's no reason to check what the command name is since it's already handled by discordjs-commando

    run(message) {
        const args = message.content.split(" ");
        args.shift();
    
        const subject = args[0];
    
        if (!subject) {
            return message.say("Open what?")
        } else if (subject === "door") {
            return message.say("Opening door");
        }
    }