Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Member): support member-specific banners #174

Merged
merged 1 commit into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3709,6 +3709,7 @@ declare namespace Dysnomia {
addRole(roleID: string, reason?: string): Promise<void>;
ban(options?: BanMemberOptions): Promise<void>;
dynamicAvatarURL(format?: ImageFormat, size?: number): string;
dynamicBannerURL(format?: ImageFormat, size?: number): string | null;
edit(options: MemberOptions, reason?: string): Promise<void>;
kick(reason?: string): Promise<void>;
removeRole(roleID: string, reason?: string): Promise<void>;
Expand Down
30 changes: 21 additions & 9 deletions lib/structures/Member.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ class Member extends Base {
if(data.flags !== undefined) {
this.flags = data.flags;
}
if(data.banner !== undefined) {
/**
* The hash of the member's guild-specific banner, or null if no banner
* @type {String?}
*/
this.banner = data.banner;
}
if(data.user !== undefined) {
this.user.update(data.user);
}
Expand All @@ -169,20 +176,12 @@ class Member extends Base {
return this.avatar ? this.guild.shard.client._formatImage(Endpoints.GUILD_AVATAR(this.guild.id, this.id, this.avatar)) : this.user.avatarURL;
}

/**
* The hash of the user's banner, or null if no banner (REST only)
* @type {String?}
*/
get banner() {
return this.user.banner;
}

/**
* The URL of the user's banner
* @type {String?}
*/
get bannerURL() {
return this.user.bannerURL;
return this.banner ? this.guild.shard.client._formatImage(Endpoints.BANNER(this.id, this.banner)) : this.user.bannerURL;
}

/**
Expand Down Expand Up @@ -332,6 +331,19 @@ class Member extends Base {
return this.guild.shard.client._formatImage(Endpoints.GUILD_AVATAR(this.guild.id, this.id, this.avatar), format, size);
}

/**
* Get the user's banner with the given format and size
* @param {String} [format] The filetype of the banner ("jpg", "jpeg", "png", "gif", or "webp")
* @param {Number} [size] The size of the banner (any power of two between 16 and 4096)
* @returns {String?}
*/
dynamicBannerURL(format, size) {
if(!this.banner) {
return this.user.dynamicBannerURL(format, size);
}
return this.guild.shard.client._formatImage(Endpoints.BANNER(this.id, this.banner), format, size);
}

/**
* Edit the guild member
* @param {Object} options The properties to edit
Expand Down