MG91
MG91

Reputation: 193

Discordjs how to find user then add role

I have a web app where the user can submit a form and after they do I want to grant them a role on my discord.

on Nodejs I have this code:

discordClient.users.fetch('1222333444').roles.add('123456789');

but I get:

Cannot read property 'add' of undefined

I tried multiple ways to do it but none of them worked unfortunately, the all use discordClient.on('message'

Which is not what I am looking for.

Upvotes: 0

Views: 496

Answers (1)

Aykut Saraç
Aykut Saraç

Reputation: 140

You can do that way in v12:

const guild = client.guilds.cache.get("guildid");
const member = guild.members.cache.get("memberid")
member.roles.add("roleid");

Upvotes: 1

Related Questions