如何在twitch bot中分离变量

时间:2018-06-16 13:33:35

标签: javascript node.js twitch

我正在尝试这样做,所以我可以在我的twitch bot注册这个的第二部分:!test [var]。基本上如果他们说!测试@jeff它可以打招呼@jeff。

我正在使用tmi

client.on('chat', function(channel, user, message, self) {
    if(message === "!twitter") {
        client.action("kong_plays", user['display-name'] + " my twitter is x !");
    }
    if(message === "!youtube") {
        client.action("kong_plays", user['display-name'] + " my youtube is x !");
    }
    if(message === "!discord") {
        client.action("kong_plays", user['display-name'] + " you can join my discord with the link : https://discord.gg/GdbZea !");
    }
    if(message === "!sub") {
        client.action("kong_plays", user['display-name'] + " It helps me out if you can sub. Also you receive access to exclusive perks such as: Sub Games, Sub only emotes, Sub Only Discord. Sub here x !");
    }
    if(message === "!tip") {
        client.action("kong_plays", user['display-name'] + " Tipping helps me out a ton whether it be only $1 x !");
    }
    if(message === "!alerts") {
        client.action("kong_plays", user['display-name'] + " The alerts are shown in chat as I stream with shadowplay not allowing me to show alerts!");

    }
    if(//someone inputs !test [var] ) {
        register [var]
        say something + [var]
    }

1 个答案:

答案 0 :(得分:1)

也许只是用空格分割得到不同的词:

const [command, ...args] = message.split(" ");

所以你可以像访问它一样访问它:

if(command === "!test") {
  client.action("idk", "Hello " + args[0] + "!");
}