public async Task ShowLeaderBoard(CommandContext context) { using IBotAccessProvider provider = this.providerBuilder.Build(); List <GuildKarmaRecord> leaderboardRecords = provider.GetGuildKarmaRecords(context.Guild.Id) .OrderByDescending(record => record.CurrentKarma).ToList(); int requestorRanking = leaderboardRecords.FindIndex(record => record.UserId == context.User.Id) + 1; StringBuilder leaderboardBuilder = new StringBuilder() .AppendLine("```") .AppendLine($"Your rank: {requestorRanking}") .AppendLine(new string('-', 20)); int index = 1; foreach (GuildKarmaRecord record in leaderboardRecords) { try { DiscordMember member = await context.Guild.GetMemberAsync(record.UserId); leaderboardBuilder.AppendLine($"{index}. {member.DisplayName} - {record.CurrentKarma} karma"); index++; if (index > 10) { break; } } catch (NotFoundException) { } } leaderboardBuilder.Append("```"); await context.RespondAsync(leaderboardBuilder.ToString()); }