Learn to Code via Tutorials on Repl.it!

← Back to all posts
Difference between a User and a GuildMember (discord.js)
almostStatic

Welcome

I've seen this issue pop up everywhere, even in the Official Discord.js Server

I'm sure many of you have received the error cannot read property 'hasRole' of undefined when you do something like message.author.hasRole()?

That's because a message.author is a User, not a GuildMember.

They key difference between them, is, that a GuidMember has access to roles, permissions and nicknames... and, message.author is a User, not a GuidMember.

If you wish for you to be able to add roles, or perform GuildMember methods or access properties on a message author, you'd do message.member, this represents the message.author as a GuildMember in the guild which this message belongs to.

Voters
MarcosDJ
Codemonkey51
almostStatic
Comments
hotnewtop
Codemonkey51

Cool!

almostStatic
Codemonkey51

:)@almostStatic