Reputation: 31
Ok, for some reason, I tested something just to see if it would work and it gave me an error. I can't figure out what's wrong, it looks fine to me, I've compared and searched for an hour and nothing. I could be doing something really stupid but here. This is bot.js
const botSettings = require("./botsettings.json");
console.log(botSettings.token);
console.log(botSettings.prefix);
This is package.json
{
"name": "ultibot",
"version": "0.0.1",
"description": "a bot for the discord server The Ritual",
"main": "bot.js",
"author": "Rituliant",
"license": "ISC",
"dependencies": {
"discord.js": "^11.3.0"
}
}
This is botsettings.json
{
"token": "thisisnormallyalongstringofrandomletters",
"prefix": "!",
}
The full error is this
module.js:665
throw err;
^
SyntaxError: C:\Users\quinb\DiscordBotJS\botsettings.json: Unexpected token } in JSON at position 98
at JSON.parse (<anonymous>)
at Object.Module._extensions..json (module.js:662:27)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (C:\Users\quinb\DiscordBotJS\bot.js:1:83)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
Upvotes: 1
Views: 2973
Reputation: 1074258
JSON, unlike modern JavaScript, does not allow trailing commas in its object notation. So the final }
in botsettings.json
is indeed unexpected, because of the comma before it:
{ "token": "thisisnormallyalongstringofrandomletters", "prefix": "!", ^----- Here }
That's only valid JSON if you remove that comma:
{
"token": "thisisnormallyalongstringofrandomletters",
"prefix": "!"
}
Upvotes: 1
Reputation: 17844
botsettings.json should be
{
"token": "thisisnormallyalongstringofrandomletters",
"prefix": "!"
}
i.e. no comma after the prefix value.
Upvotes: 2