public async Task AssignLeagueFARoles(ISocketMessageChannel channel, IGuild guild) { int remaining = _latestValues.Where(x => x[0].ToString() != "").Count(); Dictionary <string, int> _assignedCounters = new Dictionary <string, int>(); var message = await channel.SendMessageAsync("", false, Embeds.AssigningLeagueRoles(remaining, _assignedCounters)); await GetLatestValues().ConfigureAwait(false); string errorLog = ""; for (int row = 1; row < _latestValues.Count; row++) { var signup = _latestValues[row]; if (signup[(int)ColumnIDs.Discord].ToString() == "") { continue; } ulong discordId = ulong.Parse(signup[(int)ColumnIDs.Discord].ToString()); if (signup[(int)ColumnIDs.ApplicationStatus].ToString() != "Approved and Notified") { continue; } string league = signup[(int)ColumnIDs.League].ToString(); var user = await guild.GetUserAsync(discordId); if (user is null) { errorLog += $"{signup[(int)ColumnIDs.Name]}: User left Discord\r\n"; continue; } if (user.RoleIds.Any(x => x == 472145107056066580)) { league = "GM (Skipped)"; } if (_assignedCounters.ContainsKey(league)) { _assignedCounters[league]++; } else { _assignedCounters.Add(league, 1); } if (league == "GM (Skipped)") { continue; } try { } catch (Exception ex) { if (ex.Message.ToLower().Contains("forbidden")) { errorLog += $"{signup[(int)ColumnIDs.Name]}: Permission Error\r\n"; } else { errorLog += $"{signup[(int)ColumnIDs.Name]}: {ex.Message}\r\n"; } } remaining--; if (row % 100 == 0) { await message.ModifyAsync(x => x.Embed = Embeds.AssigningLeagueRoles(remaining, _assignedCounters) ); } await Task.Delay(1500); } await message.ModifyAsync( x => x.Embed = Embeds.AssigningLeagueRoles(remaining, _assignedCounters) ); if (errorLog.Length > 2000) { File.WriteAllText(@"./DiscordErrorLog.log", errorLog); await channel.SendFileAsync(@"./DiscordErrorLog.log", ""); } else { await channel.SendMessageAsync("", false, Embeds.ErrorLog(errorLog)).ConfigureAwait(false); } }