Optimize Add/RemoveRolesAsync methods (#2614)
This commit is contained in:
@@ -81,14 +81,18 @@ namespace Discord.Rest
|
||||
|
||||
public static async Task AddRolesAsync(IGuildUser user, BaseDiscordClient client, IEnumerable<ulong> roleIds, RequestOptions options)
|
||||
{
|
||||
foreach (var roleId in roleIds)
|
||||
await client.ApiClient.AddRoleAsync(user.Guild.Id, user.Id, roleId, options).ConfigureAwait(false);
|
||||
await client.ApiClient.ModifyGuildMemberAsync(user.GuildId, user.Id, args: new()
|
||||
{
|
||||
RoleIds = user.RoleIds.Except(new[] { user.Guild.Id }).Concat(roleIds).Distinct().ToArray()
|
||||
}, options);
|
||||
}
|
||||
|
||||
public static async Task RemoveRolesAsync(IGuildUser user, BaseDiscordClient client, IEnumerable<ulong> roleIds, RequestOptions options)
|
||||
{
|
||||
foreach (var roleId in roleIds)
|
||||
await client.ApiClient.RemoveRoleAsync(user.Guild.Id, user.Id, roleId, options).ConfigureAwait(false);
|
||||
await client.ApiClient.ModifyGuildMemberAsync(user.GuildId, user.Id, args: new()
|
||||
{
|
||||
RoleIds = user.RoleIds.Except(new[] { user.Guild.Id }).Except(roleIds).ToArray()
|
||||
}, options);
|
||||
}
|
||||
|
||||
public static async Task SetTimeoutAsync(IGuildUser user, BaseDiscordClient client, TimeSpan span, RequestOptions options)
|
||||
|
||||
Reference in New Issue
Block a user