Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在twitch机器人中分离变量_Javascript_Node.js_Twitch - Fatal编程技术网

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

Javascript 如何在twitch机器人中分离变量,javascript,node.js,twitch,Javascript,Node.js,Twitch,我正在努力做到这一点,这样我就可以在我的twitch机器人中注册这个的第二部分:!测试[var]。基本上如果他们说!测试@jeff,它可以向@jeff打招呼 我正在使用tmi client.on('chat', function(channel, user, message, self) { if(message === "!twitter") { client.action("kong_plays", user['display-name'] + " my twitte

我正在努力做到这一点,这样我就可以在我的twitch机器人中注册这个的第二部分:!测试[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]
    }

也许只需按空格分开,就可以得到不同的单词:

const [command, ...args] = message.split(" ");
因此,您可以通过以下方式访问它:

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

返回以下内容:
const[command,…args]=message.split(“”)
引用错误:未定义消息