简体   繁体   中英

On join, bot gives pre determined role

I have a command the gets the ID of a role and stores it (joinrole)

client.on('guildMemberAdd', (guildMember) => {
   guildMember.addRole(guildMember.guild.roles.find(role => role.name === "joinrole"));
});

how do I define the joinrole and make the bot give that specific role

The addRole method is deprecated and removed in Discord.js V12.x. So you should use the .add() method to add roles on guild members. This code should do it:

client.on('guildMemberAdd', (guildMember) => {
    const RoleToGiveNewMembers = guildMember.guild.roles.cache.get("RoleID");

    if(RoleToGiveNewMembers) {
        /**
         * Role found
         * We found a role to give to the user.
        */
       guildMember.roles.add(RoleToGiveNewMembers);
    }
});

There is also a nice guide for upgrading and using Discord.js V12. Updating from v11 to v12 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM