Question about getting a user from his ID
In short I get the userid from the database with mutes and pass it to
const member = guild.members.cache.get(row.id);
but when the bot needs to remove the role, it logs me an error:
02/27 11:14:01 [Bot] member.roles.remove(mutedRoleId);
27.02 11:14:01 [Bot] ^
02/27 11:14:01 [Bot] TypeError: Cannot read properties of undefined (reading 'roles')
14 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
- ✅
Marked as resolved by OPDocumentation suggestion for @/|ĶÎŦÃŖŮ|:
:method: GuildMemberManager#fetch()
Fetches member(s) from a guild.
27.02 11:51:31 [Bot] member.roles.remove(mutedRoleId);
27.02 11:51:31 [Bot] ^
27.02 11:51:31 [Bot] TypeError: Cannot read properties of undefined (reading 'remove')
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
i reading that
and trying
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
guild.removeRole(row.id, mutedRoleId)
Something like this?
Unknown User•10mo ago
Message Not Public
Sign In & Join Server To View
oh
guild.removeRole({ user: member, role: mutedRole });
27.02 12:06:46 [Bot] ^
27.02 12:06:46 [Bot] TypeError: guild.removeRole is not a function
I think
Fetch is a async func
I add await
and it work now