'How do you give a user a role by role ID in Discord.JS V13 (latest)

I'm trying to make a verification bot for my new Discord server, but I need to know how to assign roles in Discord.JS 13 latest.



Solution 1:[1]

You can do this something like same thing with getting member.id.

const member = message.mentions.members.first() || message.guild.members.cache.get(args[0])

You can create the code similar to this.

const role = message.mentions.roles.first() || message.guild.roles.cache.get(args[0])

Now you can adjust your code file:

const member = message.mentions.members.first() || message.guild.members.cache.get(args[0])
const role = message.mentions.roles.first() || message.guild.roles.cache.get(args[1])

member.roles.add(role) //To add the mentioned or given role id the the member.

You can see the image below, the format is args[0] for member and args[1] is for role. Try to experiment your code for this time!

                                       Example add role

Solution 2:[2]

It's GuildMember.roles.add(roleOrRoles, [optionalReason]). In the discord.js docs: docs: -addrole.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 æ–°Acesyyy
Solution 2 panzer-chan