1

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',);

stirious
  • 24
  • 5
  • @Σπύρος Γούλας wouldn't this script just replace the text and not capture the data after the add command, sorry if I am mis-understanding I am a bit of a beginner with javascript. – stirious Jun 21 '20 at 15:11
  • It would effectively remove the "!add" from the message and the latter would end up containing only the rest. "!add stirious" would be " stritious" (notice the empty space that was not removed). So the data after the command remains intact and is stored in the 'arguments' variable. If you want to also remove the empty string after the command use message.replace("!add ", ""); – Prinny Jun 21 '20 at 16:07

1 Answers1

1

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
}
Prinny
  • 208
  • 6
  • 16