Discord.js unexpected token error?


#1

I’m trying to make a little chatbot for Discord, but there seems to be something wrong with the config file. Whenever I try to get the bot to go online, the console gives me this:
module.js:674
throw err;
^
SyntaxError: /app/config.json: Unexpected token p in JSON at position 13
at JSON.parse ()
at Object.Module._extensions…json (module.js:671:27)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object. (/app/server.js:5:16)
at Module._compile (module.js:652:30)
at Object.Module._extensions…js (module.js:663:10)

could anyone help me? I’m relatively new to Javascript and even more new to Glitch.


#2

Remove that join link and reset your bot token, also i think i fixed your problem


#3

That got rid of the error, thank you!! But now when I try to start it on the console, it doesn’t say anything at all. It just skips a line and gives me the $ again. The bot hasn’t gone online.

In the log, it said
node v8.11.4, with pnpm
Installing…
Resolving: total 48, reused 48, downloaded 0
WARN discord.js@11.4.2 requires a peer of bufferutil@^3.0.3 but none was installed.
WARN discord.js@11.4.2 requires a peer of erlpack@discordapp/erlpack but none was installed.
There are about eight of those warnings. I used the “add package” button (there’s a red box with 17? I don’t know what that means) to add all of them, but it’s still not working. Is there something else I’m missing?


#4

Those “Warns” are normal for Installing a package with a discord.js in it but what do you mean the (dollar sign) ? the $ is a git console and works just like a cmd. To START your bot you need to type node bot.js (Replace Bot.js With What Ever File You Have To Start The Bot.)

When you start the console you have to manually type those commands to start your bot.


#5

I don’t think I explained that well enough, oops! But yeah, I know that. I typed ‘node server.js’ and pressed enter, but nothing happened. No error message, nothing.

I just tried it again so I could show a screenshot, and this time I got “(node:28013) Warning: N-API is an experimental feature and could change at any time.” and nothing else.


(Before it was the same, but the warning wasn’t there)


#6

It looks like that the server.js is 1 not responding because theres a error and its not showing since you didnt add a if error throw error command

or 2. The server.js is not making the other scripts or commands start which means they dont work and ends up crashing.


#7

Okay… how would I fix either of those?


#8

1.Add this to your server.js
.catch(console.error);

This should display any error.


#9

I added that, but then the error was “parsing error: unexpected token .” I removed the . and then it was “unexpected token catch” I wrote it at the very beginning, should it be somewhere else?


#10

Show the code first maybe i can help?


#11

Fixed issues check now


#12

Thank you! It seems like the bot should be online now, but it isn’t? Now this error is showing:
events.js:183
throw er; // Unhandled ‘error’ event
^
Error: listen EADDRINUSE :::3000
at Object._errnoException (util.js:992:11)
at _exceptionWithHostPort (util.js:1014:20)
at Server.setupListenHandle [as _listen2] (net.js:1355:14)
at listenInCluster (net.js:1396:12)
at Server.listen (net.js:1480:7)
at Function.listen (/rbd/pnpm-volume/7d309165-e155-4cdd-b6b1-c8d7401d2570/node_modules/.registry.npmjs.org/express/4.16.3/node_modules/express/lib/
application.js:618:24)
at Object. (/app/server.js:12:5)
at Module._compile (module.js:652:30)
at Object.Module._extensions…js (module.js:663:10)
at Module.load (module.js:565:32)


#13

That’s happening because something is already listening on port 3000. Do you have another server running?


#14

Yes, but how would I change the port number so it would work on any server?

When I activate the bot from my computer’s console (and the code is in the computer’s files), I don’t need to include the port anywhere in the code and it works just fine on multiple servers at once.