所以我现在已经尝试将这项工作做了大约3个小时,而我几乎放弃了。
我目前的代码是:
var tmi = require('tmi.js');
var linksDisallowed = ["http://", "https://", ".dk"];
var options = {
options: {
debug: true
},
connection: {
cluster: "aws",
reconnect: true
},
identity: {
username: "botstormen",
password: "**CENSORED FOR SECURITY REASONS**"
},
channels: ["dunkstormen"]
};
var client = new tmi.client(options);
client.connect();
client.on('connected', function(adress, port) {
client.action("dunkstormen", "joinede chatten og er klar til at hjælpe! :3");
});
client.on('chat', function(channel, user, message, self) {
if(message === "!social" || message === "!Social") {
client.action("dunkstormen", "Twitter: twitter.com/dunkstormen Facebook: facebook.com/dunkstormen");
}
});
client.on('chat', function(channel, user, message, self) {
for (var i = 0; i < 3; i++) {
if(message.indexOf(linksDisallowed[i]) >= 0) {
client.say("Hello, " + user);
}
}
});
但每当我输入数组中的一个单词时,链接被允许进入聊天,僵尸就会立即崩溃并出现以下错误:
C:\Users\Benjamin Jørgensen\Desktop\botstormen\node_modules\tmi.js\lib\commands.js:207
if (message.toLowerCase().startsWith("/me ") || message.toLowerCase().startsWith("\\me ")) {
^
TypeError: Cannot read property 'toLowerCase' of undefined
at client.say (C:\Users\Benjamin Jørgensen\Desktop\botstormen\node_modules\tmi.js\lib\commands.js:207:20)
at client.<anonymous> (C:\Users\Benjamin Jørgensen\Desktop\botstormen\app.js:37:11)
at client.EventEmitter.emit (C:\Users\Benjamin Jørgensen\Desktop\botstormen\node_modules\tmi.js\lib\events.js:99:50)
at client.handleMessage (C:\Users\Benjamin Jørgensen\Desktop\botstormen\node_modules\tmi.js\lib\client.js:792:34)
at C:\Users\Benjamin Jørgensen\Desktop\botstormen\node_modules\tmi.js\lib\client.js:919:18
at Array.forEach (native)
at client._onMessage (C:\Users\Benjamin Jørgensen\Desktop\botstormen\node_modules\tmi.js\lib\client.js:917:11)
at WebSocket.onMessage (C:\Users\Benjamin Jørgensen\Desktop\botstormen\node_modules\tmi.js\node_modules\ws\lib\WebSocket.js:442:14)
at emitTwo (events.js:87:13)
at WebSocket.emit (events.js:172:7)
答案 0 :(得分:1)
tmi.js命令say
有2个参数,你只传递一个。
https://docs.tmijs.org/v0.0.29/Commands.html#say
将client.say("Hello, " + user);
更改为client.say(channel,"Hello, " + user);
编辑以帮助评论:
根据文档,https://docs.tmijs.org/v0.0.29/Events.html#chat聊天事件返回一个用户对象。下面有一个用户对象的描述,其中有关于它的通知可以更改......但您现在肯定可以执行此操作:将user
替换为user.username
。
如果它不起作用,请检查用户对象以找到您应该使用的正确属性。
答案 1 :(得分:0)
这意味着您的app.js
没有向tmi.js服务发送消息