Add GetRoleUserCounts REST method (#3195)

This commit is contained in:
Mihail Gribkov
2025-10-19 19:09:19 +03:00
committed by GitHub
parent 5ca29fd461
commit dade9b2df6
5 changed files with 29 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
using Discord.Audio; using Discord.Audio;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Immutable;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using System.Threading.Tasks; 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"/>. /// A task that represents the asynchronous creation operation. The task result contains a <see cref="BulkBanResult"/>.
/// </returns> /// </returns>
Task<BulkBanResult> BulkBanAsync(IEnumerable<ulong> userIds, int? deleteMessageSeconds = null, RequestOptions options = null); 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);
} }
} }

View File

@@ -1711,6 +1711,15 @@ namespace Discord.API
return await SendJsonAsync<GuildIncidentsData>("PUT", () => $"guilds/{guildId}/incident-actions", args, ids, options: options).ConfigureAwait(false); 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 #endregion
#region Guild Bans #region Guild Bans

View File

@@ -651,6 +651,13 @@ namespace Discord.Rest
return model is null ? null : RestRole.Create(client, guild, model); 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 #endregion
#region Users #region Users

View File

@@ -412,6 +412,10 @@ namespace Discord.Rest
/// <inheritdoc /> /// <inheritdoc />
public Task<BulkBanResult> BulkBanAsync(IEnumerable<ulong> userIds, int? deleteMessageSeconds = null, RequestOptions options = null) public Task<BulkBanResult> BulkBanAsync(IEnumerable<ulong> userIds, int? deleteMessageSeconds = null, RequestOptions options = null)
=> GuildHelper.BulkBanAsync(this, Discord, userIds.ToArray(), deleteMessageSeconds, options); => GuildHelper.BulkBanAsync(this, Discord, userIds.ToArray(), deleteMessageSeconds, options);
/// <inheritdoc />
public Task<ImmutableDictionary<ulong, int>> GetRoleUserCountsAsync(RequestOptions options = null)
=> GuildHelper.GetRoleUserCountsAsync(this, Discord, options);
#endregion #endregion
#region Channels #region Channels

View File

@@ -1187,6 +1187,9 @@ namespace Discord.WebSocket
return sticker; return sticker;
return null; return null;
} }
/// <inheritdoc />
public Task<ImmutableDictionary<ulong, int>> GetRoleUserCountsAsync(RequestOptions options = null)
=> GuildHelper.GetRoleUserCountsAsync(this, Discord, options);
#endregion #endregion
#region Users #region Users