Skip to content

Commit

Permalink
feat: allow guild emoji to be set as role icon
Browse files Browse the repository at this point in the history
  • Loading branch information
iShibi committed Sep 30, 2021
1 parent 1044788 commit 4c465dd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
15 changes: 12 additions & 3 deletions src/managers/RoleManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class RoleManager extends CachedManager {
* @property {PermissionResolvable} [permissions] The permissions for the new role
* @property {number} [position] The position of the new role
* @property {boolean} [mentionable] Whether or not the new role should be mentionable
* @property {?(BufferResolvable|Base64Resolvable)} [icon] The icon for the role
* @property {?(BufferResolvable|Base64Resolvable|EmojiResolvable)} [icon] The icon for the role
* @property {?string} [unicodeEmoji] The name of the unicode emoji for the role
* @property {string} [reason] The reason for creating this role
*/
Expand Down Expand Up @@ -134,7 +134,10 @@ class RoleManager extends CachedManager {
let { name, color, hoist, permissions, position, mentionable, reason, icon, unicodeEmoji } = options;
if (color) color = resolveColor(color);
if (typeof permissions !== 'undefined') permissions = new Permissions(permissions);
if (icon) icon = await DataResolver.resolveImage(icon);
if (icon) {
const guildEmojiURL = this.guild.emojis.resolve(icon)?.url;
icon = guildEmojiURL ? await DataResolver.resolveImage(guildEmojiURL) : await DataResolver.resolveImage(icon);
}

const data = await this.client.api.guilds(this.guild.id).roles.post({
data: {
Expand Down Expand Up @@ -188,13 +191,19 @@ class RoleManager extends CachedManager {
});
}

let icon = data.icon;
if (typeof icon !== 'undefined') {
const guildEmojiURL = this.guild.emojis.resolve(icon)?.url;
icon = guildEmojiURL ? await DataResolver.resolveImage(guildEmojiURL) : await DataResolver.resolveImage(icon);
}

const _data = {
name: data.name,
color: typeof data.color === 'undefined' ? undefined : resolveColor(data.color),
hoist: data.hoist,
permissions: typeof data.permissions === 'undefined' ? undefined : new Permissions(data.permissions),
mentionable: data.mentionable,
icon: typeof data.icon === 'undefined' ? undefined : await DataResolver.resolveImage(data.icon),
icon,
unicode_emoji: data.unicodeEmoji,
};

Expand Down
4 changes: 2 additions & 2 deletions src/structures/Role.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class Role extends Base {
* @property {number} [position] The position of the role
* @property {PermissionResolvable} [permissions] The permissions of the role
* @property {boolean} [mentionable] Whether or not the role should be mentionable
* @property {?(BufferResolvable|Base64Resolvable)} [icon] The icon for the role
* @property {?(BufferResolvable|Base64Resolvable|EmojiResolvable)} [icon] The icon for the role
* @property {?string} [unicodeEmoji] The name of the unicode emoji for the role
*/

Expand Down Expand Up @@ -308,7 +308,7 @@ class Role extends Base {

/**
* Sets a new icon for the role.
* @param {?(BufferResolvable|Base64Resolvable)} icon The icon for the role
* @param {?(BufferResolvable|Base64Resolvable|EmojiResolvable)} icon The icon for the role
* @param {string} [reason] Reason for changing the role's icon
* @returns {Promise<Role>}
*/
Expand Down
4 changes: 2 additions & 2 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1636,7 +1636,7 @@ export class Role extends Base {
public setMentionable(mentionable?: boolean, reason?: string): Promise<Role>;
public setName(name: string, reason?: string): Promise<Role>;
public setPermissions(permissions: PermissionResolvable, reason?: string): Promise<Role>;
public setIcon(icon: BufferResolvable | Base64Resolvable | null, reason?: string): Promise<Role>;
public setIcon(icon: BufferResolvable | Base64Resolvable | EmojiResolvable | null, reason?: string): Promise<Role>;
public setPosition(position: number, options?: SetRolePositionOptions): Promise<Role>;
public setUnicodeEmoji(unicodeEmoji: string | null, reason?: string): Promise<Role>;
public toJSON(): unknown;
Expand Down Expand Up @@ -4655,7 +4655,7 @@ export interface RoleData {
position?: number;
permissions?: PermissionResolvable;
mentionable?: boolean;
icon?: BufferResolvable | Base64Resolvable | null;
icon?: BufferResolvable | Base64Resolvable | EmojiResolvable | null;
unicodeEmoji?: string | null;
}

Expand Down

0 comments on commit 4c465dd

Please sign in to comment.