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:
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)
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.
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.
/app/index.js:87
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.
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 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?