private async void OnTimedBanBlacklisted(object source, ElapsedEventArgs e) { foreach (var guild in _client.Guilds) { foreach (var blacklistedId in Config.BLACKLISTED_IDS) { if (guild.GetUser(blacklistedId) != null) { if (guild.CurrentUser.GuildPermissions.BanMembers && guild.CurrentUser.Roles.OrderByDescending(x => x.Position).First().Position > guild.GetUser(blacklistedId).Roles.OrderByDescending(x => x.Position).First().Position&& guild.OwnerId != guild.GetUser(blacklistedId).Id) { await guild.AddBanAsync(guild.GetUser(blacklistedId)); } } } } using (var db = new DbContext()) { var guildRepo = new GuildRepository(db); foreach (var dbGuild in guildRepo.GetAll()) { if (_client.GetGuild(dbGuild.Id) != null && Config.BLACKLISTED_IDS.Any(x => x == _client.GetGuild(dbGuild.Id).OwnerId)) { await _client.GetGuild(dbGuild.Id).LeaveAsync(); } } } }