Discord bot not working anymore

My bot went down a few months ago, but I didn’t really feel like looking into it until a few weeks ago. Since I am using my bot to manage certain roles, I’d like to get it back online. I looked at some solutions online, but unfortunately they didn’t help and therefore I’m searching for help from here.
This is the error that the log shows:

} catch {

SyntaxError: Unexpected token {
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:617:28)
at Object.Module._extensions…js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object. (/rbd/pnpm-volume/b9079535-b68d-418e-a29d-990603c321bf/node_modules/.registry.npmjs.org/discord.js/12.1.1/node_modules/discord.js/src/index.js:8:11)

Hey @Kuldz,

Try changing the Node version in your package.json to 12.x.


discord.js now require node 12 or later, and v12 is the latest one on Glitch

1 Like

Hey @Kuldz,

Please show some more of the source code for Client.js so that we can resolve your issue! You seem to have a syntactical error somewhere in there.

1 Like

The Node version changing helped, thank you guys for that. I was also forced to modify my commands and things a bit since things have obviously changed. Though now I have another problem… kinda. As mentioned above, my bot manages certain roles. Well, apparently glitch log says that I have errors somewhere when trying to get users roles, but apparently the code works just fine? I tried it out in my server multiple times and my bot changes the roles if necessary, but according to glitch, something is still messed up.

It seems like you have an extra } or just some syntax error.

Can you paste the main form of the function that end in the 41 line, including the catch error handler?

Specify your errors you got so we can help you :slight_smile:

Yep, provide errors like Jarvo said.

Recently Discord.JS v12 switched from } catch(e) { to } catch {, the latter only works in Node v12 and up.

This is the error that I get, even after trying to fix everything that had been changed in 12.x. And for some reason it doesn’t constantly throw the error in the logs as well.

if (message.member.roles.cache.get(“495xxxxxxxxxxxx292”)) { //Level 1

TypeError: Cannot read property ‘roles’ of null
Jump Toat RoleChange (/app/index.js:87:24)
Jump Toat Client. (/app/index.js:168:3)
at Client.emit (events.js:201:15)
at MessageCreateAction.handle (/rbd/pnpm-volume/b9079535-b68d-418e-a29d-990603c321bf/node_modules/.registry.npmjs.org/discord.js/12.1.1/node_modules/discord.js/src/client/actions/MessageCreate.js:31:14)
at Object.module.exports [as MESSAGE_CREATE] (/rbd/pnpm-volume/b9079535-b68d-418e-a29d-990603c321bf/node_modules/.registry.npmjs.org/discord.js/12.1.1/node_modules/discord.js/src/client/websocket/handlers/MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (/rbd/pnpm-volume/b9079535-b68d-418e-a29d-990603c321bf/node_modules/.registry.npmjs.org/discord.js/12.1.1/node_modules/discord.js/src/client/websocket/WebSocketManager.js:386:31)
at WebSocketShard.onPacket (/rbd/pnpm-volume/b9079535-b68d-418e-a29d-990603c321bf/node_modules/.registry.npmjs.org/discord.js/12.1.1/node_modules/discord.js/src/client/websocket/WebSocketShard.js:435:22)
at WebSocketShard.onMessage (/rbd/pnpm-volume/b9079535-b68d-418e-a29d-990603c321bf/node_modules/.registry.npmjs.org/discord.js/12.1.1/node_modules/discord.js/src/client/websocket/WebSocketShard.js:293:10)
at WebSocket.onMessage (/rbd/pnpm-volume/b9079535-b68d-418e-a29d-990603c321bf/node_modules/.registry.npmjs.org/ws/7.2.3/node_modules/ws/lib/event-target.js:120:16)
at WebSocket.emit (events.js:196:13)

I’ll throw a part of the code in as well, so you can tell me if I’ve done anything wrong. The code is actually longer, but if I get this part fixed then everything should be fixed.

client.on(“message”, message => {
function RoleChange() {
if (message.member.roles.cache.get(“495xxxxxxxxxxxx292”)) { //Level 1
message.member.roles.remove(“500xxxxxxxxxxxx841”); //Level 0
message.member.roles.add(“500xxxxxxxxxxxx017”); //Level 1-10
} else setTimeout(RoleChange, 1000 * 10);


Also, thank you for all the help so far. I usually don’t like to ask help from online (especially from forums) since I feel pretty dumb doing so, because my code shouldn’t be that hard to fix. Then again, I don’t really have any JS experience.

I don’t see anything specific. Just try checking to see if all of them have a match.

I do not see the error neither. I assume you have something wrong in the code you didn’t send because I test your code and it work.

Anyway I do not recommend you to do this

setTimeout(RoleChange, 1000 * 10);

It will keep looping forever for every time the command is triggered for users that do not have the role 495xxxxxxxxxxxx292. Kind like a nightmare for your script

I’m pretty sure it can’t be anything else, because the error seems to be in the roles part of the line according to the log and rest of the code literally looks the same, it’s just continuing with higher levels and they all work the same way as the code part that I put above does. What would you recommending instead of the setTimeout(RoleChange, 1000 * 10); though? I remember back in the day when I wrote this it wouldn’t work without something like that, what would the better alternative be?

Looks like you have an extra character after catch.