Skip to content

Commit 466b491

Browse files
authored
GetRoleAsync W (#2989)
1 parent 2aaa0fd commit 466b491

File tree

5 files changed

+47
-0
lines changed

5 files changed

+47
-0
lines changed

src/Discord.Net.Core/Entities/Guilds/IGuild.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,17 @@ public interface IGuild : IDeletable, ISnowflakeEntity
953953
/// A role that is associated with the specified <paramref name="id"/>; <see langword="null" /> if none is found.
954954
/// </returns>
955955
IRole GetRole(ulong id);
956+
957+
/// <summary>
958+
/// Gets a role in this guild.
959+
/// </summary>
960+
/// <param name="id">The snowflake identifier for the role.</param>
961+
/// <returns>
962+
/// A task that represents the asynchronous creation operation. The task result contains the role
963+
/// that is associated with the specified <paramref name="id"/>; <see langword="null" /> if none is found.
964+
/// </returns>
965+
Task<IRole> GetRoleAsync(ulong id, RequestOptions options = null);
966+
956967
/// <summary>
957968
/// Creates a new role with the provided name.
958969
/// </summary>

src/Discord.Net.Rest/DiscordRestApiClient.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,17 @@ public Task RemoveRoleAsync(ulong guildId, ulong userId, ulong roleId, RequestOp
790790
var ids = new BucketIds(guildId: guildId);
791791
return SendAsync("DELETE", () => $"guilds/{guildId}/members/{userId}/roles/{roleId}", ids, options: options);
792792
}
793+
794+
public Task<API.Role> GetRoleAsync(ulong guildId, ulong roleId, RequestOptions options = null)
795+
{
796+
Preconditions.NotEqual(guildId, 0, nameof(guildId));
797+
Preconditions.NotEqual(roleId, 0, nameof(roleId));
798+
options = RequestOptions.CreateOrClone(options);
799+
800+
var ids = new BucketIds(guildId: guildId);
801+
return SendAsync<API.Role>("GET", () => $"guilds/{guildId}/roles/{roleId}", ids, options: options);
802+
}
803+
793804
#endregion
794805

795806
#region Channel Messages

src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,13 @@ public static async Task<RestRole> CreateRoleAsync(IGuild guild, BaseDiscordClie
644644

645645
return RestRole.Create(client, guild, model);
646646
}
647+
648+
public static async Task<RestRole> GetRoleAsync(IGuild guild, BaseDiscordClient client, ulong roleId, RequestOptions options)
649+
{
650+
var model = await client.ApiClient.GetRoleAsync(guild.Id, roleId, options).ConfigureAwait(false);
651+
return model is null ? null : RestRole.Create(client, guild, model);
652+
}
653+
647654
#endregion
648655

649656
#region Users

src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,6 +1596,15 @@ async Task<IInviteMetadata> IGuild.GetVanityInviteAsync(RequestOptions options)
15961596
/// <inheritdoc />
15971597
IRole IGuild.GetRole(ulong id)
15981598
=> GetRole(id);
1599+
1600+
/// <inheritdoc cref="IGuild.GetRole" />
1601+
public Task<RestRole> GetRoleAsync(ulong id, RequestOptions options = null)
1602+
=> GuildHelper.GetRoleAsync(this, Discord, id, options);
1603+
1604+
/// <inheritdoc />
1605+
async Task<IRole> IGuild.GetRoleAsync(ulong id, RequestOptions options)
1606+
=> await GetRoleAsync(id);
1607+
15991608
/// <inheritdoc />
16001609
async Task<IRole> IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options)
16011610
=> await CreateRoleAsync(name, permissions, color, isHoisted, false, options).ConfigureAwait(false);

src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,6 +2200,15 @@ async Task<IInviteMetadata> IGuild.GetVanityInviteAsync(RequestOptions options)
22002200
/// <inheritdoc />
22012201
IRole IGuild.GetRole(ulong id)
22022202
=> GetRole(id);
2203+
2204+
/// <inheritdoc cref="IGuild.GetRole" />
2205+
public Task<RestRole> GetRoleAsync(ulong id, RequestOptions options = null)
2206+
=> GuildHelper.GetRoleAsync(this, Discord, id, options);
2207+
2208+
/// <inheritdoc />
2209+
async Task<IRole> IGuild.GetRoleAsync(ulong id, RequestOptions options)
2210+
=> await GetRoleAsync(id);
2211+
22032212
/// <inheritdoc />
22042213
async Task<IRole> IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options)
22052214
=> await CreateRoleAsync(name, permissions, color, isHoisted, false, options).ConfigureAwait(false);

0 commit comments

Comments
 (0)