diff --git a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs index afa169c3..79e893e1 100644 --- a/src/Discord.Net.Core/Entities/Guilds/IGuild.cs +++ b/src/Discord.Net.Core/Entities/Guilds/IGuild.cs @@ -953,6 +953,17 @@ namespace Discord /// A role that is associated with the specified ; if none is found. /// IRole GetRole(ulong id); + + /// + /// Gets a role in this guild. + /// + /// The snowflake identifier for the role. + /// + /// A task that represents the asynchronous creation operation. The task result contains the role + /// that is associated with the specified ; if none is found. + /// + Task GetRoleAsync(ulong id, RequestOptions options = null); + /// /// Creates a new role with the provided name. /// diff --git a/src/Discord.Net.Rest/DiscordRestApiClient.cs b/src/Discord.Net.Rest/DiscordRestApiClient.cs index 407a4447..36558d37 100644 --- a/src/Discord.Net.Rest/DiscordRestApiClient.cs +++ b/src/Discord.Net.Rest/DiscordRestApiClient.cs @@ -790,6 +790,17 @@ namespace Discord.API var ids = new BucketIds(guildId: guildId); return SendAsync("DELETE", () => $"guilds/{guildId}/members/{userId}/roles/{roleId}", ids, options: options); } + + public Task GetRoleAsync(ulong guildId, ulong roleId, RequestOptions options = null) + { + Preconditions.NotEqual(guildId, 0, nameof(guildId)); + Preconditions.NotEqual(roleId, 0, nameof(roleId)); + options = RequestOptions.CreateOrClone(options); + + var ids = new BucketIds(guildId: guildId); + return SendAsync("GET", () => $"guilds/{guildId}/roles/{roleId}", ids, options: options); + } + #endregion #region Channel Messages diff --git a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs index 563bf32a..ac9dce12 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs @@ -644,6 +644,13 @@ namespace Discord.Rest return RestRole.Create(client, guild, model); } + + public static async Task GetRoleAsync(IGuild guild, BaseDiscordClient client, ulong roleId, RequestOptions options) + { + var model = await client.ApiClient.GetRoleAsync(guild.Id, roleId, options).ConfigureAwait(false); + return model is null ? null : RestRole.Create(client, guild, model); + } + #endregion #region Users diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs index f0ca5093..5911c14d 100644 --- a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs +++ b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs @@ -1596,6 +1596,15 @@ namespace Discord.Rest /// IRole IGuild.GetRole(ulong id) => GetRole(id); + + /// + public Task GetRoleAsync(ulong id, RequestOptions options = null) + => GuildHelper.GetRoleAsync(this, Discord, id, options); + + /// + async Task IGuild.GetRoleAsync(ulong id, RequestOptions options) + => await GetRoleAsync(id); + /// async Task IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options) => await CreateRoleAsync(name, permissions, color, isHoisted, false, options).ConfigureAwait(false); diff --git a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs index bb6c3748..ae434bbe 100644 --- a/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs +++ b/src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs @@ -2200,6 +2200,15 @@ namespace Discord.WebSocket /// IRole IGuild.GetRole(ulong id) => GetRole(id); + + /// + public Task GetRoleAsync(ulong id, RequestOptions options = null) + => GuildHelper.GetRoleAsync(this, Discord, id, options); + + /// + async Task IGuild.GetRoleAsync(ulong id, RequestOptions options) + => await GetRoleAsync(id); + /// async Task IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options) => await CreateRoleAsync(name, permissions, color, isHoisted, false, options).ConfigureAwait(false);