Guild.member()
returns the GuildMember form of a User object, if the user is present in the guild. It takes a UserResolvable
as a parameter (user ID or object).
GuildMemberManager
resolves a GuildMemberResolvable
to a GuildMember object. What confused me is that a GuildMemberResolvable
can be either a GuildMember object or a UserResolvable
.
First of all, why would anybody need to convert a GuildMember object into a GuildMember object?
Seconds of all, besides the option of resolving a GuildMember object as well as a UserResolvable
, is there any difference between the two methods? They look exactly the same to me.
const user = message.mentions.users.first(); // a user object const guild = message.client.guilds.cache.get('Guild ID'); // a guild object guild.member(user); // a guildmember object guild.members.resolve(user); // also a guildmember object
Advertisement
Answer
The two methods are identical.
The source for Guild#member
shows that it simply calls GuildMemberManager#resolve
:
member(user) { return this.members.resolve(user); }
UserResolvable
and GuildMemberResolvable
are also the same. UserResolvable
can be a User
, Snowflake
, Message
, or GuildMember
; and a GuildMemberResolvable
can be a GuildMember
or UserResolvable
. In this way, the type GuildMemberResolvable
is essentially redundant and could be substituted for UserResolvable
.
// Using TypeScript syntax to show the types type UserResolvable = User | Snowflake | Message | GuildMember // same as GuildMember | User | Snowflake | Message type GuildMemberResolvable = GuildMember | UserResolvable