Skip to content

Commit

Permalink
Change TryGetMemberAsync to actually be async and return DiscordMember?
Browse files Browse the repository at this point in the history
  • Loading branch information
byterand committed Aug 13, 2024
1 parent 5209ac6 commit 7dff813
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions DisCatSharp/Entities/Guild/DiscordGuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1780,35 +1780,30 @@ public async Task<DiscordMember> GetMemberAsync(ulong userId, bool fetch = false
/// Gets a member of this guild by their user ID.
/// </summary>
/// <param name="userId">ID of the member to get.</param>
/// <param name="member">The member object.</param>
/// <param name="fetch">Whether to fetch the member from the api prior to cache.</param>
/// <returns><see langword="true"/> if the member was found, <paramref name="member"/> will be a <see cref="DiscordMember"/> entity, otherwise <see langword="false"/> and <see langword="null"/>.</returns>
/// <returns>The requested <see cref="DiscordMember"/> if the member was found, otherwise <see langword="null"/>.</returns>
/// <exception cref="ServerErrorException">Thrown when Discord is unable to process the request.</exception>
public bool TryGetMemberAsync(ulong userId, out DiscordMember? member, bool fetch = false)
public async Task<DiscordMember?> TryGetMemberAsync(ulong userId, bool fetch = false)
{
if (!fetch && this.MembersInternal != null && this.MembersInternal.TryGetValue(userId, out var mbr))
{
member = mbr;
return true;
}
return mbr;

try
{
member = this.Discord.ApiClient.GetGuildMemberAsync(this.Id, userId).Result;
mbr = await this.Discord.ApiClient.GetGuildMemberAsync(this.Id, userId).ConfigureAwait(false);
}
catch (NotFoundException)
{
member = null;
return false;
return null;
}

var intents = this.Discord.Configuration.Intents;

if (intents.HasIntent(DiscordIntents.GuildMembers))
if (this.MembersInternal != null)
this.MembersInternal[userId] = member;
this.MembersInternal[userId] = mbr;

return true;
return mbr;
}

/// <summary>
Expand Down

0 comments on commit 7dff813

Please sign in to comment.