如何在 twitch 机器人中分离变量

How to seperate a variable in a twitch bot

我正在努力做到这一点,这样我就可以在我的 twitch 机器人中注册第二部分:!test [var]。基本上如果他们说 !test @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  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]
    }

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

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

因此您可以像这样访问它:

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