I am currently making a discord bot in javascript but it wont run. Whenever i attemp to run it it shows this error message
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)
it is saying the error is on line 114 but my code only has 113 lines. 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..
}
}
;
I am pretty new to java script and coding for a discord bot so i dont know why this won't work
You are missing a closing parenthesis before the final semicolon
The last lines of your code should be
break;
// Just add any case commands if you want to..
}
}
);
Generally, your formatting is a mess and makes it very hard to spot such errors. Think about using an IDE with automatic formatting.
In both
else {bot.sendMessage({to: channelID, message: 'It is a tie!'});
lines there are missing closing brackets.
And please clean up that Code a bit, and you will find the errors all by yourself. :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.