diff --git a/src/Discord.Net.Core/Entities/Roles/RoleProperties.cs b/src/Discord.Net.Core/Entities/Roles/RoleProperties.cs index 93cda8d5b..b6399c054 100644 --- a/src/Discord.Net.Core/Entities/Roles/RoleProperties.cs +++ b/src/Discord.Net.Core/Entities/Roles/RoleProperties.cs @@ -1,3 +1,5 @@ +using System; + namespace Discord { /// @@ -50,11 +52,24 @@ namespace Discord /// This value may not be set if the role is an @everyone role. /// public Optional Hoist { get; set; } - /// /// Gets or sets the icon of the role. /// - public Optional Icon { get; set; } + /// + /// This value cannot be set at the same time as Emoji, as they are both exclusive. + /// + /// Setting an Icon will override a currently existing Emoji if present. + /// + public Optional Icon { get; set; } + /// + /// Gets or sets the unicode emoji of the role. + /// + /// + /// This value cannot be set at the same time as Icon, as they are both exclusive. + /// + /// Setting an Emoji will override a currently existing Icon if present. + /// + public Optional Emoji { get; set; } /// /// Gets or sets whether or not this role can be mentioned. /// diff --git a/src/Discord.Net.Rest/API/Rest/ModifyGuildRoleParams.cs b/src/Discord.Net.Rest/API/Rest/ModifyGuildRoleParams.cs index fbb9c3e48..8aa92d40d 100644 --- a/src/Discord.Net.Rest/API/Rest/ModifyGuildRoleParams.cs +++ b/src/Discord.Net.Rest/API/Rest/ModifyGuildRoleParams.cs @@ -14,7 +14,9 @@ namespace Discord.API.Rest [JsonProperty("hoist")] public Optional Hoist { get; set; } [JsonProperty("icon")] - public Optional Icon { get; set; } + public Optional Icon { get; set; } + [JsonProperty("unicode_emoji")] + public Optional Emoji { get; set; } [JsonProperty("mentionable")] public Optional Mentionable { get; set; } } diff --git a/src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs b/src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs index d8552f869..3b2946a0d 100644 --- a/src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs +++ b/src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs @@ -13,15 +13,20 @@ namespace Discord.Rest { await client.ApiClient.DeleteGuildRoleAsync(role.Guild.Id, role.Id, options).ConfigureAwait(false); } - public static async Task ModifyAsync(IRole role, BaseDiscordClient client, + public static async Task ModifyAsync(IRole role, BaseDiscordClient client, Action func, RequestOptions options) { var args = new RoleProperties(); func(args); - if (args.Icon.IsSpecified) + if (args.Icon.IsSpecified || args.Emoji.IsSpecified) { role.Guild.Features.EnsureFeature(GuildFeature.RoleIcons); + + if (args.Icon.IsSpecified && args.Emoji.IsSpecified) + { + throw new ArgumentException("Emoji and Icon properties cannot be present on a role at the same time."); + } } var apiArgs = new API.Rest.ModifyGuildRoleParams @@ -31,8 +36,20 @@ namespace Discord.Rest Mentionable = args.Mentionable, Name = args.Name, Permissions = args.Permissions.IsSpecified ? args.Permissions.Value.RawValue.ToString() : Optional.Create(), - Icon = args.Icon.IsSpecified ? args.Icon.Value.ToModel() : Optional.Unspecified + Icon = args.Icon.IsSpecified ? args.Icon.Value.Value.ToModel() : Optional.Unspecified, + Emoji = args.Emoji.GetValueOrDefault()?.Name ?? Optional.Unspecified }; + + if (args.Icon.IsSpecified && role.Emoji != null) + { + apiArgs.Emoji = null; + } + + if (args.Emoji.IsSpecified && !string.IsNullOrEmpty(role.Icon)) + { + apiArgs.Icon = null; + } + var model = await client.ApiClient.ModifyGuildRoleAsync(role.Guild.Id, role.Id, apiArgs, options).ConfigureAwait(false); if (args.Position.IsSpecified)