簡體   English   中英

我收到一條錯誤消息,提示該行不存在

[英]I am getting an error message for a line that isnt there

我目前正在用JavaScript制作Discord機器人,但無法運行。 每當我嘗試運行它時,都會顯示此錯誤消息

C:\Users\user\Documents\--Discord robo--\bot.js:114
});
 ^

SyntaxError: Unexpected token )
    at new Script (vm.js:84:7)
    at createScript (vm.js:264:10)
    at Object.runInThisContext (vm.js:312:10)
    at Module._compile (internal/modules/cjs/loader.js:684:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
    at Module.load (internal/modules/cjs/loader.js:620:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
    at Function.Module._load (internal/modules/cjs/loader.js:552:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:774:12)
    at executeUserCode (internal/bootstrap/node.js:499:15)

這是說錯誤在第114行,但是我的代碼只有113行。 https://pastebin.com/AwEz01Nt

   var Discord = require('discord.io');
var logger = require('winston');
var auth = require('./auth.json');
// Configure logger settings
logger.remove(logger.transports.Console);
logger.add(new logger.transports.Console, {
    colorize: true
});
logger.level = 'debug';
// Initialize Discord Bot
var bot = new Discord.Client({
   token: auth.token,
   autorun: true
});
bot.on('ready', function (evt) {
    logger.info('Connected');
    logger.info('Logged in as: ');
    logger.info(bot.username + ' - (' + bot.id + ')');

});
bot.on('message', function (user, userID, channelID, message, evt) {
    // Our bot needs to know if it will execute a command
    // It will listen for messages that will start with `!`

    if (message.substring(0, 1, 2) == '!') {
        var args = message.substring(1).split(' ');
        var cmd = args[0];
        var in1 = args[1];}

        args = args.splice(1);
        switch(cmd) {


            // !ping
            case 'ping':
                bot.sendMessage({
                    to: channelID,
                    message: 'Pong!'
                });
            break;


            // !commands
            case 'commands':
                bot.sendMessage({
                    to: channelID,
                    message: 'The current commands are: ping, commands, random and rps and the current prefix is h.'
                });
            break;


            // !random
        case 'random':
        var randomnumber; // setting the randomnumber variable
        var upper;
        upper = in1 ;
        randomnumber = Math.floor(Math.random() * Math.floor(in1));
        bot.sendMessage({to: channelID, message: 'Your random number from 1 to ' + in1 + ' is ' + randomnumber});
        break;


     // !rps
        case 'rps': //if the code is rps
            var in2;
            rpsrandom = Math.random();
            if ( rpsrandom <= 1/3 ) { in2 = 'rock' ;}
            if ( rpsrandom >= 2/3 ) {in2 = 'scissors' ;}
            else {in2 = 'paper';}
            bot.sendMessage({to: channelID, message: in2});
                if (in1 == 'r')//if in1 is rock
                { 
                    if (in2 == 'paper'){
                        bot.sendMessage({to: channelID, message: 'You lose!'});
                        break;
                    }
                    if (in2 == 'scissors'){
                        bot.sendMessage({to: channelID, message: 'You win!'});
                        break;
                    }
                    else {bot.sendMessage({to: channelID, message: 'It is a tie!'});
                    break;
                }
                if (in1 == 'p') //if in1 is rock
                { 
                    if (in2 == 'scissors'){
                        bot.sendMessage({to: channelID, message: 'You lose!'});
                        break;
                    }
                    if (in2 == 'rock'){
                        bot.sendMessage({to: channelID, message: 'You win!'});
                        break;
                    }
                    else {bot.sendMessage({to: channelID, message: 'It is a tie!'});
                    break;
                }
                if (in1 == 's')//if in1 is rock
                { 
                    if (in2 == 'rock'){
                        bot.sendMessage({to: channelID, message: 'You lose!'});
                        break;
                    }
                    if (in2 == 'paper'){
                        bot.sendMessage({to: channelID, message: 'You win!'});
                        break;
                    }
                    else {bot.sendMessage({to: channelID, message: 'It is a tie!'});
                    break;
                }
        break;  
            // Just add any case commands if you want to..
         }
    }
;

我對Java腳本和不和諧的bot編碼很陌生,所以我不知道為什么這不起作用

您在最后的分號前缺少右括號

您代碼的最后幾行應該是

break;  
            // Just add any case commands if you want to..
         }
    }
);

通常,格式很亂,很難發現此類錯誤。 考慮使用具有自動格式化功能的IDE。

同時

else {bot.sendMessage({to: channelID, message: 'It is a tie!'});

行中缺少右括號。

並且請稍微整理一下該代碼,您將自己發現所有錯誤。 :)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM