mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 16:43:31 +01:00
feat(GuildMember): add guild avatars (#5696)
Co-authored-by: Sugden <28943913+NotSugden@users.noreply.github.com> Co-authored-by: Shubham Parihar <shubhamparihar391@gmail.com> Co-authored-by: GoldenAngel <50855202+GoldenAngel2@users.noreply.github.com>
This commit is contained in:
@@ -71,6 +71,15 @@ class GuildMember extends Base {
|
||||
}
|
||||
|
||||
if ('nick' in data) this.nickname = data.nick;
|
||||
if ('avatar' in data) {
|
||||
/**
|
||||
* The guild member's avatar hash
|
||||
* @type {?string}
|
||||
*/
|
||||
this.avatar = data.avatar;
|
||||
} else if (typeof this.avatar !== 'string') {
|
||||
this.avatar = null;
|
||||
}
|
||||
if ('joined_at' in data) this.joinedTimestamp = new Date(data.joined_at).getTime();
|
||||
if ('premium_since' in data) {
|
||||
this.premiumSinceTimestamp = data.premium_since ? new Date(data.premium_since).getTime() : null;
|
||||
@@ -112,6 +121,26 @@ class GuildMember extends Base {
|
||||
return this.guild.voiceStates.cache.get(this.id) ?? new VoiceState(this.guild, { user_id: this.id });
|
||||
}
|
||||
|
||||
/**
|
||||
* A link to the member's guild avatar.
|
||||
* @param {ImageURLOptions} [options={}] Options for the Image URL
|
||||
* @returns {?string}
|
||||
*/
|
||||
avatarURL({ format, size, dynamic } = {}) {
|
||||
if (!this.avatar) return null;
|
||||
return this.client.rest.cdn.GuildMemberAvatar(this.guild.id, this.id, this.avatar, format, size, dynamic);
|
||||
}
|
||||
|
||||
/**
|
||||
* A link to the member's guild avatar if they have one.
|
||||
* Otherwise, a link to their {@link User#displayAvatarURL} will be returned.
|
||||
* @param {ImageURLOptions} [options={}] Options for the Image URL
|
||||
* @returns {string}
|
||||
*/
|
||||
displayAvatarURL(options) {
|
||||
return this.avatarURL(options) ?? this.user.displayAvatarURL(options);
|
||||
}
|
||||
|
||||
/**
|
||||
* The time this member joined the guild
|
||||
* @type {?Date}
|
||||
@@ -323,6 +352,7 @@ class GuildMember extends Base {
|
||||
this.guild.id === member.guild.id &&
|
||||
this.joinedTimestamp === member.joinedTimestamp &&
|
||||
this.nickname === member.nickname &&
|
||||
this.avatar === member.avatar &&
|
||||
this.pending === member.pending &&
|
||||
(this._roles === member._roles ||
|
||||
(this._roles.length === member._roles.length && this._roles.every((role, i) => role === member._roles[i])))
|
||||
@@ -341,12 +371,15 @@ class GuildMember extends Base {
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return super.toJSON({
|
||||
const json = super.toJSON({
|
||||
guild: 'guildId',
|
||||
user: 'userId',
|
||||
displayName: true,
|
||||
roles: true,
|
||||
});
|
||||
json.avatarURL = this.avatarURL();
|
||||
json.displayAvatarURL = this.displayAvatarURL();
|
||||
return json;
|
||||
}
|
||||
|
||||
// These are here only for documentation purposes - they are implemented by TextBasedChannel
|
||||
|
||||
Reference in New Issue
Block a user