using DSharpPlus; using DSharpPlus.Entities; namespace X10D.DSharpPlus; /// /// Extension methods for . /// public static class DiscordMemberExtensions { /// /// Returns a value indicating whether this member has the specified role. /// /// The member whose roles to search. /// The role for which to check. /// /// if has the role; otherwise, . /// public static bool HasRole(this DiscordMember member, DiscordRole role) { #if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(member); ArgumentNullException.ThrowIfNull(role); #else if (member is null) { throw new ArgumentNullException(nameof(member)); } if (role is null) { throw new ArgumentNullException(nameof(role)); } #endif return member.Roles.Contains(role); } /// /// Normalizes a so that the internal client is assured to be a specified value. /// /// The to normalize. /// The target client. /// /// A whose public values will match , but whose internal client /// is . /// /// /// is /// -or- /// is /// public static async Task NormalizeClientAsync(this DiscordMember member, DiscordClient client) { #if NET6_0_OR_GREATER ArgumentNullException.ThrowIfNull(member); ArgumentNullException.ThrowIfNull(client); #else if (member is null) { throw new ArgumentNullException(nameof(member)); } if (client is null) { throw new ArgumentNullException(nameof(client)); } #endif DiscordGuild guild = await member.Guild.NormalizeClientAsync(client).ConfigureAwait(false); return await guild.GetMemberAsync(member.Id).ConfigureAwait(false); } }