简体   繁体   中英

Can't get role with discord.js

I'm working on a Discord bot with discord.js . The code below is supposed to give a selected user a certain role.

const roleTag = message.guild.roles.cache.find(role => role.name === '<role name>');
const member = message.mentions.members.first();
member.roles.add(role);

But every time I get an error saying:

TypeError: Cannot read property 'roles' of undefined

Note: The message object has no problem (I checked it)

Where do you get the error, in the add function or defining roleTag? Btw, you are bot adding the defined role, you are adding role and you have it named roleTag

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