2016-12-14 22 views
-5

これを検索してコードを何度も見てきましたが、何が原因なのかわからないようです。 if文の後に誰かがセミコロンを置いたときに普通に起こるようですが、if文の後には(私が盲目的でない限り)何も持っていないので、わかりません。私はJavascriptとnode.jsを使って簡単なDiscordボットをコーディングしていますJavascript "SyntaxError:予期しないトークンelse"

/Users/Nyro/Desktop/Thax/digger.js:64 else ^^^^ SyntaxError: Unexpected token else at Object.exports.runInThisContext (vm.js:76:16) at Module._compile (module.js:542:28) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.runMain (module.js:604:10) at run (bootstrap_node.js:394:7) at startup (bootstrap_node.js:149:9) at bootstrap_node.js:509:3

(私はその下にあるすべてのものはエラーに重要かそうでないかはわからないけど、彼らはそこにいる):私はボットを起動するターミナルに入るたびに、私はこのエラーを得続けます。 また、64行目はコード内の他の多くの行と同じです(なぜなら、多くの単語が異なる単語に対して繰り返されているからです)。なぜその領域に焦点が当てられているのかわかりません。

if ((messageauthor == botname) == false){ // to prevent spamming to oblivion 

    if (dofilter('cupcake')) 
    { 
     sendimpeccablemessage('Message1'); 
    } 
    else 

    if (dofilter('linus')) 
    { 
     if (Math.floor(Math.random()*3)) 
     {sendimpeccablemessage('Message2');} 
     else 
     {sendimpeccablemessage('Message3');} 
     else 
     {sendimpeccablemessage('Message4');} 
    } 
    else 

私は(彼は実際に私にファイルを送信されることはありません)コードをテストしながら、私の友人が撮ったスクリーンショットから、このコードを持って:とにかく、ここではその領域内のコードです。これは完全なコードではなく、問題があるように見える部分だけですが、コードの残りの部分は基本的に同じです(一部はランダムな選択肢があり、そうでないものもあります)。

答えて

1

あなたには2つのelse文があります。 if/else if/elseを行うことはできますが、/ else/elseを実行することはできません。

if (Math.floor(Math.random()*3)) 
     {sendimpeccablemessage('Message2');} 
else 
     {sendimpeccablemessage('Message3');} 
else 
     {sendimpeccablemessage('Message4');} 

フォーマットも混乱します。これは実行順序を示すので、常にブラケットを入れています。

if ((messageauthor == botname) == false) { 
    // to prevent spamming to oblivion 
    if (dofilter('cupcake')) { 
     sendimpeccablemessage('Message1'); 
    } 
    else { 
    if (dofilter('linus')) { 
      if (Math.floor(Math.random()*3)) {  
       sendimpeccablemessage('Message2'); 
      } 
      else { 
       sendimpeccablemessage('Message3'); 
      } 
      //else{ 
      //  sendimpeccablemessage('Message4');} 
     }  

    } 
} 
else { 

} 

Why I put brackets in.

+0

質問にはあなたの答えに同じ問題がありますか? –

+0

私はそれを再フォーマットしていました。 – kemiller2002

2

あなたはここ2つのelse文があります:else ifであるか、または最後を削除する必要があり

if (Math.floor(Math.random()*3)) 
    {sendimpeccablemessage('Message2');} 
    else 
    {sendimpeccablemessage('Message3');} 
    else 
    {sendimpeccablemessage('Message4');} 

真ん中を。

関連する問題