node.js – Adding a role to user from client Id string?

I am creating my discord.js bot along side my express.js app and have a validation page that requires the user to submit their unique code generated when they join the discord server, in other words I would like to add a role to the guild member when they have successfully input the code on the webapp.

I have a database collecting their user id. Is there a way I can fetch a guild member from their user id to add to a role in my “guild”/discord server? I have attempted numerous ways to fetch the user to set a role though it will log Cannot read properties of undefined (reading 'cache') no matter what method I am using. Any help in the right direction would be great, I have left the source code to said project below along with the validation page I am using to validate the code that is generated on GuildMemberAdd.

Regards,
codibez

GitHub repository | validation page

Read more here: Source link