I’m having trouble with my Discord bot application. When I try to launch it using my batch file, I keep getting a syntax error message that points to an arrow function. The error shows up right at the ready event handler and says there’s an unexpected token.
Here’s the error output I’m seeing:
bot.on('ready', () => {
^
SyntaxError: Unexpected token )
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
My bot code looks like this:
const Discord = require("discord.js");
const bot = new Discord.Client();
bot.login('your-token-here')
bot.on('ready', () => {
console.log(`Bot is online as ${bot.user.username}!`);
});
bot.on('message', message => {
if (message.content === 'hello') {
message.reply('Hi there!');
}
});
bot.login('your-actual-token');
Your Node.js version is the problem. Arrow functions weren’t supported until Node.js 4.0, and you’re running 0.12.2 which is ancient. I hit this exact issue maintaining an older server. You’ve got two options: upgrade Node.js to something current (I’d go with Node 16+ for Discord.js compatibility), or rewrite your arrow functions the old way. Quick fix: change bot.on('ready', () => { to bot.on('ready', function() { and bot.on('message', message => { to bot.on('message', function(message) {. But honestly, just upgrade Node.js - modern Discord.js versions need newer Node anyway.
This issue you’re encountering is definitely due to the Node.js version you’re using, which is 0.12.2. Arrow functions were introduced in ES6, so that older version can’t parse the => syntax at all. While you could rewrite your functions to use the standard function syntax as a workaround, it’s not a lasting solution. To ensure compatibility with Discord.js and other modern libraries, upgrading to at least Node 14 is highly recommended. Doing so will enhance your experience and prevent further issues with JavaScript features.
yeah, that node version is way too old for discord bots tbh. also noticed you’re calling bot.login() twice in your code which will cause issues later. just remove the first one and keep only the second login call at the bottom.