GetRoleAsync W (#2989)

This commit is contained in:
Mihail Gribkov
2024-08-29 11:22:58 +03:00
committed by GitHub
parent 2aaa0fd2ff
commit 466b491c3c
5 changed files with 47 additions and 0 deletions

View File

@@ -953,6 +953,17 @@ namespace Discord
/// A role that is associated with the specified <paramref name="id"/>; <see langword="null" /> if none is found. /// A role that is associated with the specified <paramref name="id"/>; <see langword="null" /> if none is found.
/// </returns> /// </returns>
IRole GetRole(ulong id); IRole GetRole(ulong id);
/// <summary>
/// Gets a role in this guild.
/// </summary>
/// <param name="id">The snowflake identifier for the role.</param>
/// <returns>
/// A task that represents the asynchronous creation operation. The task result contains the role
/// that is associated with the specified <paramref name="id"/>; <see langword="null" /> if none is found.
/// </returns>
Task<IRole> GetRoleAsync(ulong id, RequestOptions options = null);
/// <summary> /// <summary>
/// Creates a new role with the provided name. /// Creates a new role with the provided name.
/// </summary> /// </summary>

View File

@@ -790,6 +790,17 @@ namespace Discord.API
var ids = new BucketIds(guildId: guildId); var ids = new BucketIds(guildId: guildId);
return SendAsync("DELETE", () => $"guilds/{guildId}/members/{userId}/roles/{roleId}", ids, options: options); return SendAsync("DELETE", () => $"guilds/{guildId}/members/{userId}/roles/{roleId}", ids, options: options);
} }
public Task<API.Role> 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<API.Role>("GET", () => $"guilds/{guildId}/roles/{roleId}", ids, options: options);
}
#endregion #endregion
#region Channel Messages #region Channel Messages

View File

@@ -644,6 +644,13 @@ namespace Discord.Rest
return RestRole.Create(client, guild, model); return RestRole.Create(client, guild, model);
} }
public static async Task<RestRole> 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 #endregion
#region Users #region Users

View File

@@ -1596,6 +1596,15 @@ namespace Discord.Rest
/// <inheritdoc /> /// <inheritdoc />
IRole IGuild.GetRole(ulong id) IRole IGuild.GetRole(ulong id)
=> GetRole(id); => GetRole(id);
/// <inheritdoc cref="IGuild.GetRole" />
public Task<RestRole> GetRoleAsync(ulong id, RequestOptions options = null)
=> GuildHelper.GetRoleAsync(this, Discord, id, options);
/// <inheritdoc />
async Task<IRole> IGuild.GetRoleAsync(ulong id, RequestOptions options)
=> await GetRoleAsync(id);
/// <inheritdoc /> /// <inheritdoc />
async Task<IRole> IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options) async Task<IRole> IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options)
=> await CreateRoleAsync(name, permissions, color, isHoisted, false, options).ConfigureAwait(false); => await CreateRoleAsync(name, permissions, color, isHoisted, false, options).ConfigureAwait(false);

View File

@@ -2200,6 +2200,15 @@ namespace Discord.WebSocket
/// <inheritdoc /> /// <inheritdoc />
IRole IGuild.GetRole(ulong id) IRole IGuild.GetRole(ulong id)
=> GetRole(id); => GetRole(id);
/// <inheritdoc cref="IGuild.GetRole" />
public Task<RestRole> GetRoleAsync(ulong id, RequestOptions options = null)
=> GuildHelper.GetRoleAsync(this, Discord, id, options);
/// <inheritdoc />
async Task<IRole> IGuild.GetRoleAsync(ulong id, RequestOptions options)
=> await GetRoleAsync(id);
/// <inheritdoc /> /// <inheritdoc />
async Task<IRole> IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options) async Task<IRole> IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options)
=> await CreateRoleAsync(name, permissions, color, isHoisted, false, options).ConfigureAwait(false); => await CreateRoleAsync(name, permissions, color, isHoisted, false, options).ConfigureAwait(false);