dcthang23
dcthang23

Reputation: 15

Having problem with Discord.js addRole() Function

I want my Discord bot to set role as the user input corresponding role args, e.g: !role btcm, !role nccm, etc.

I'm having a problem with the discord.js addRole() function as I can't see its documentation on discord.js.org. The console show TypeError: member.addRole is not a function

module.exports = message => {
    const member = message.member;

    switch(message.content.split(" ")[1]){
        case "btcm":
            roleID = "THE ID No.1"
        case "nccm":
            roleID = "THE ID No.2"
        case "guest":
            roleID = "THE ID No.3"

        let roleAtts = message.guild.roles.cache.get(roleID);
        member.addRole(roleAtts);
        channel.send("Successfully set a role");
    }
}

Upvotes: 1

Views: 107

Answers (2)

Syntle
Syntle

Reputation: 5174

Since discord.js v12, you need to use roles.add() instead of addRole()

member.roles.add(roleAtts);

Upvotes: 2

duckboycool
duckboycool

Reputation: 2455

The method is member.roles.add() instead of member.addRole().

Upvotes: 1

Related Questions