Search code examples
javascriptnode.jstwitchtwitch-api

How can I capture text after a if (message == "...") in javascript


I am trying to make a twitch bot using javascript and tmi.js and I need to make a command that can capture the data after someone says the word !add, I don't know what module to use in this case, any ideas?

client.on("chat", (channel, user, message, self) => {
    if (message == "!add")
    fs.appendFile('test.txt', game + ", ", function (err) {
        if (err) throw err
        client.say (Titles,"added!", 'utf8',);


Solution

  • Instead of checking if the message is a command, you can check if the message contains a command, strip the command away and keep the command arguments.

    if (message.includes("!add")) {
      let arguments= message.replace("!add", "");
    
      //check what arguments contain and do what you want
    }