Add GetRoleUserCounts REST method (#3195)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Discord.Audio;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
@@ -1469,5 +1470,10 @@ namespace Discord
|
||||
/// A task that represents the asynchronous creation operation. The task result contains a <see cref="BulkBanResult"/>.
|
||||
/// </returns>
|
||||
Task<BulkBanResult> BulkBanAsync(IEnumerable<ulong> userIds, int? deleteMessageSeconds = null, RequestOptions options = null);
|
||||
|
||||
/// <summary>
|
||||
/// Gets a mapping of role IDs to the number of users that have each role.
|
||||
/// </summary>
|
||||
Task<ImmutableDictionary<ulong, int>> GetRoleUserCountsAsync(RequestOptions options = null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1711,6 +1711,15 @@ namespace Discord.API
|
||||
return await SendJsonAsync<GuildIncidentsData>("PUT", () => $"guilds/{guildId}/incident-actions", args, ids, options: options).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<Dictionary<ulong, int>> GetRoleUserCountsAsync(ulong guildId, RequestOptions options = null)
|
||||
{
|
||||
Preconditions.NotEqual(guildId, 0, nameof(guildId));
|
||||
|
||||
var ids = new BucketIds(guildId: guildId);
|
||||
|
||||
return await SendAsync<Dictionary<ulong, int>>("GET", () => $"guilds/{guildId}/roles/member-counts", ids, options: options);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Guild Bans
|
||||
|
||||
@@ -651,6 +651,13 @@ namespace Discord.Rest
|
||||
return model is null ? null : RestRole.Create(client, guild, model);
|
||||
}
|
||||
|
||||
public static async Task<ImmutableDictionary<ulong, int>> GetRoleUserCountsAsync(IGuild guild, BaseDiscordClient client, RequestOptions options = null)
|
||||
{
|
||||
var model = await client.ApiClient.GetRoleUserCountsAsync(guild.Id, options);
|
||||
return model.ToImmutableDictionary();
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Users
|
||||
|
||||
@@ -412,6 +412,10 @@ namespace Discord.Rest
|
||||
/// <inheritdoc />
|
||||
public Task<BulkBanResult> BulkBanAsync(IEnumerable<ulong> userIds, int? deleteMessageSeconds = null, RequestOptions options = null)
|
||||
=> GuildHelper.BulkBanAsync(this, Discord, userIds.ToArray(), deleteMessageSeconds, options);
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<ImmutableDictionary<ulong, int>> GetRoleUserCountsAsync(RequestOptions options = null)
|
||||
=> GuildHelper.GetRoleUserCountsAsync(this, Discord, options);
|
||||
#endregion
|
||||
|
||||
#region Channels
|
||||
|
||||
@@ -1187,6 +1187,9 @@ namespace Discord.WebSocket
|
||||
return sticker;
|
||||
return null;
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public Task<ImmutableDictionary<ulong, int>> GetRoleUserCountsAsync(RequestOptions options = null)
|
||||
=> GuildHelper.GetRoleUserCountsAsync(this, Discord, options);
|
||||
#endregion
|
||||
|
||||
#region Users
|
||||
|
||||
Reference in New Issue
Block a user