从参数撤回用户信息

时间:2019-01-15 10:54:09

标签: node.js twitch

最近几天,我为我的一个朋友创建了一个抽动聊天机器人,但是在创建用于提供主持人有关聊天用户详细信息的命令时遇到了问题。该命令应该像这样!whois工作,然后显示通常将如下显示的所有详细信息:

"{ badges: { moderator: '1' },
 color: '#8A2BE2',
 'display-name': 'CoolDisplayName',
 emotes: null,
 flags: null,
 id: '12345678-90ab-cdef-ghij-klmnopqrstuv',
 mod: true,
 'room-id': '123456789',
 subscriber: false,
 'tmi-sent-ts': '1234567890123',
 turbo: false,
 'user-id': '123456789',
 'user-type': 'mod',
 'emotes-raw': null,
 'badges-raw': 'moderator/1',
 username: 'randomname',
 'message-type': 'chat' }"

但是我却收到以下错误:

"C:\Users\User\node_modules\tmi.js\lib\commands.js:332
        if ((message.startsWith(".") && !message.startsWith("..")) || message.startsWith("/") || message.startsWith("\\")) {
                 ^

TypeError: Cannot read property 'startsWith' of undefined
at client.say (C:\Users\User\node_modules\tmi.js\lib\commands.js:332:22)
at client.<anonymous> (C:\Users\User\Documents\Twitch Bot\app.js:37:16)
at client.EventEmitter.emit (C:\Users\User\node_modules\tmi.js\lib\events.js:101:25)
at client.EventEmitter.emits (C:\Users\User\node_modules\tmi.js\lib\events.js:64:19)
at client.handleMessage (C:\Users\User\node_modules\tmi.js\lib\client.js:880:38)
at parts.forEach (C:\Users\User\node_modules\tmi.js\lib\client.js:959:36)
at Array.forEach (<anonymous>)
at client._onMessage (C:\Users\User\node_modules\tmi.js\lib\client.js:958:11)
at WebSocket.onMessage (C:\Users\User\node_modules\ws\lib\WebSocket.js:418:14)
at WebSocket.emit (events.js:188:13)"

这是我为尝试执行该命令而创建的代码,所有敏感命令和所有不需要的命令都已被删除。

var tmi = require("tmi.js");

var options = {
    options: {
        debug: true
    },
    connection: {
        reconnect: true
    },
    identity: {
        username: "REDACTED",
        password: "oauth:REDACTED"
    },
    channels: ["#CHANNELNAME"]
};

var client = new tmi.client(options);

// Connect the client to the server..
client.connect();
client.color("GoldenRod")

client.on("chat", function (channel, user, message, self) {
    // Don't listen to my own messages..
    if (self) return;

    if (message.startsWith("!whois") && user.mod === true) {
        var input = message.split(' ')[1];
        if (input.count < 2) return;
        client.say("CHANNELNAME", input.user)    
    }
});

1 个答案:

答案 0 :(得分:0)

在代码末尾,您有以下内容:

client.say("CHANNELNAME", input.user)

但是input是一个字符串:var input = message.split(' ')[1];,因此input.user是未定义的。