Joseph presumably just wanted to go home to Daddy (and tattle).
Reuben wanted to rescue Joseph and send him back home (with a vow of silence).
One or more of the brothers wanted to kill him.
Some Midianites “happened” to come by at just the right time and Judah decided to go for the gold instead of the blood.
So Joseph ended up in Egypt.
My opinion is that this was God’s doing.
Joseph was a Ruler redemptive gift, who was pampered by his Daddy. He needed a couple of intense trainings to be able to run all of Egypt’s bureaucracy. So God controlled the timing of Reuben being assigned to the flocks, and the Midianites coming by, so that Joseph didn’t die or go home to Daddy.
Often God’s exquisite aligning of time and space we attribute to the devil. He just enrolled us in a class, without our permission, to unpack something He saw in us, that we were not unpacking.
It just might take a few years to see the beauty of His objective shining larger than the pain of the training.