Home > Software design >  Adding role discordjs 14
Adding role discordjs 14

Time:11-16

Hello I have a little problem with discordjs, I would like my bot to automatically add a role to a member just with guild and member id

But it keeps giving me the error members.find is not a function all the time

Here is the code:

const guild = client.guilds.cache.get("Server id");   

const member = guild.members.find((m) => m.id === "User id");

member.roles.cache.add(role id)

Should I do it another way?

CodePudding user response:

To add roles to a member you shouldn't use .cache because that is only used for fetching the roles that are stored in cache. Instead try doing it like this:

member.roles.add("role");

That should work.

  • Related