javascript - 如何在 twitch 机器人中分隔变量

标签 javascript node.js twitch

我正在努力做到这一点,以便我可以在我的 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 $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] + "!");
}

关于javascript - 如何在 twitch 机器人中分隔变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50888370/

相关文章:

javascript - 在 NestJS 中通过依赖注入(inject)导入 TypeScript 模块

javascript - 'book' 已定义但从未使用 MEAN 堆栈 Controller

twitch - 如何获取 Twitch 视频缩略图 URL?

ios - 在 iOS 应用程序中使用直播视频

javascript - 当模块使用 "module.exports"时扩展模块

javascript - 检查输入是否大于或小于数组值

此示例的 JavaScript 代码解释?

javascript - 如何使用 AngularJS 为每个页面从 JSON 文件加载不同部分的数据?

node.js - Nodejs 使用什么 - Sequelize 在数据库中插入时删除空格

javascript - 抽搐机器人的冷却时间