open-wa/wa-automate-nodejs

Question: How to detect word after command? #2234

justClizz posted onGitHub

How to detect word after command? Because I want to create a #ytinfo command with a link


How to detect word after command? Because I want to create a #ytinfo command with a link

I have this approach, dont know if its the best but works for me

const getMemberInfo = async (message) => {
    let body = message.body.split(' '); // split message content on spaces
    body.shift(); // remove first item from the result array (the first item is your command)
    const member = body[0]; // then you can parse command args by its indexes of the array
    if (!member) return false; // if body[0] is undefined it means that the command message has no args

    // do your stuff with the args
};
posted by danilocodes over 3 years ago

How to detect word after command? Because I want to create a #ytinfo command with a link

I have this approach, dont know if its the best but works for me

const getMemberInfo = async (message) => {
    let body = message.body.split(' '); // split message content on spaces
    body.shift(); // remove first item from the result array (the first item is your command)
    const member = body[0]; // then you can parse command args by its indexes of the array
    if (!member) return false; // if body[0] is undefined it means that the command message has no args

    // do your stuff with the args
};

ok thanks, i will try it

posted by justClizz over 3 years ago

How to detect word after command? Because I want to create a #ytinfo command with a link

I have this approach, dont know if its the best but works for me

const getMemberInfo = async (message) => {
    let body = message.body.split(' '); // split message content on spaces
    body.shift(); // remove first item from the result array (the first item is your command)
    const member = body[0]; // then you can parse command args by its indexes of the array
    if (!member) return false; // if body[0] is undefined it means that the command message has no args

    // do your stuff with the args
};

It works, thanks!

posted by justClizz over 3 years ago

Fund this Issue

$0.00
Funded

Pull requests