I've tried a lot of different methods of doing this. But I keep running into an issue where the user is returning undefined.
TypeError: Cannot read property 'addRole' of undefined
code[1]
is a discord id that I am passing through an embed which the bot is reading.
The method I am trying at the moment, is getting the guild by id, then the member by id. I did try message.guild but I was getting the same issue.
When this runs on my ID, the add roll works. However, when other members try, it returns undefined. Am I getting the member wrong?
var code = message.embeds[0].title.split( ":" );
let user_guilds = client.guilds.get( "453314772662878211" );
let user_member = user_guilds.members.get( code[1] );
user_member.addRole('455695410401640449');
Hopefully someone knows discord.js better than I do and can tell me what I'm doing wrong haha. Thanks!
Now with Discord.js version v12 it works diferent: addRole now is member.roles.add("role id ")
user_member.roles.add('roleid');