public async Task RemovePlayerAsync(IGuildUser user) { Verify.IsNotNull(user, nameof(user)); bool removedSuccessfully = false; IEnumerable <ulong> teamRoleIds = null; await this.DoReadWriteActionOnCurrentTournamentAsync( currentTournament => { if (!currentTournament.TryRemovePlayer(user.Id)) { this.Logger.Debug("Player {id} wasn't on any team", user.Id); return(this.SendChannelMessage(BotStrings.PlayerIsNotOnAnyTeam(user.Mention))); } if (currentTournament.IsTorunamentInPlayStage()) { teamRoleIds = currentTournament.TournamentRoles.TeamRoleIds.Select(kvp => kvp.Value); } removedSuccessfully = true; return(Task.CompletedTask); }); if (!removedSuccessfully) { return; } // Get the team role from the player and remove it. if (teamRoleIds != null) { IEnumerable <IRole> teamRoles = user.RoleIds.Join( teamRoleIds, id => id, id => id, (userRoleId, teamId) => this.Context.Guild.GetRole(userRoleId)); await user.RemoveRolesAsync(teamRoles, RequestOptionsSettings.Default); } this.Logger.Debug( "Player {0} was removed from the tournament. Role removed: {2}", user.Id, teamRoleIds != null); await this.SendChannelMessage(BotStrings.PlayerRemoved(user.Mention)); }