2017-12-23 7 views
1

はので、私は -say Something Hereを入力すると、それはsomeone says: Something hereを返すことボットコマンドを作成したいが、それがないすべてが戻っsomeone says: undefinedあるtmi.jsのNode.jsは

bot.on("chat", function (channel, user, message, self) { 
    if(message === "-say") 
    var code = message.split(' ')[1]; 
    bot.action("stankotomic", "someone says: " + code); 
}); 

答えて

0

のドキュメントについてはこちらを参照してください。私はあなたが間違っているかどうか教えてください。私はあなたの質問を理解しているので、それは正しい方法です。

message = "-say Something Here"とみなします。 とあなたの結果は次のようになります。

if(message === "-say") // I am 100% sure "-say" and 
//"-say something here" are different. correct me if i am wrong. 
//so we need to check for the first word, or first element in our array of words. 
//lets first create array than check: if(message.split(" ")[0] == "-say") 

var code = message.split(' ')[1]; //now, we don't have 2 spaces together 
//anywhere in our message, so array == nothing. 
//I guess it should be more like: message.split(" ").shift().join(" "); 
// this will return you: "Something Here". 

bot.action("stankotomic", "someone says: " + code); 

あなたの最終的なコード:

bot.on("chat", function (channel, user, message, self) { 
if(message.split(" ")[0] == "-say") 
     var code = message.split(" ").shift().join(" "); 
     bot.action("stankotomic", "someone says: " + code); 
}); 

PS:

はラインで、あなたのコード行を見てみましょう: "ここで何か誰かが言います"

Split documentation。

Join documentation。

Shift documentation。

0

あなたは次の行取る場合: var code = message.split(' ')[1];

を...そして、次のように変更し、それが役立つはずです: var code = message.split(' ')[1];

セパレータの引数には、split()の2つのスペースが必要です。

は、私は本当にわからないが、私はあなたが何かを意味だと思うString.prototype.split()