Holders Barcelona will begin their Copa del Rey defence against Murcia in the fourth round, while Real Madrid face third-tier Fuenlabrada.
Barca continued their dominance of the domestic cup competition last season with a third successive triumph, the 29th in their history.
A 3-1 win in the final against Alaves was Barca's second trophy of their final campaign under Luis Enrique, the Catalan giants also lifting the Supercopa de Espana.
Third division Murcia will provide the first test of this season's competition, with Ernesto Valverde's side travelling to Nueva Condomina on October 25.
Madrid have not lifted the cup since 2014, when they beat Barca 2-1 in the final. Up first for them in 2017-18 is a short trip southwest of the capital to Fuenlabrada.
After six games of the new season, Fuenlabrada are third in Group 1 of Segunda Division B and will relish welcoming Zinedine Zidane's side to the Estadio Fernando Torres.
Spain's other Champions League representatives also entered the draw, with Sevilla facing Cartagena and Atletico Madrid going up against second division Elche.
Athletic Bilbao face a trip to the Balearic Islands for a two-legged clash with Formentera, while in-form Valencia meet six-time champions Real Zaragoza.
The four all-La Liga ties see Getafe play Alaves, Deportivo La Coruna meet Las Palmas, Girona face Levante and Eibar drawn with Celta Vigo.
Draw in full:
Cartagena v Sevilla
Elche v Atletico Madrid
Murcia v Barcelona
Fuenlabrada v Real Madrid
Formentera v Athletic Bilbao
Lleida v Real Sociedad
Ponferradina v Villarreal
Real Zaragoza v Valencia
Numancia v Malaga
Valladolid v Leganes
Cadiz v Real Betis
Tenerife v Espanyol
Getafe v Alaves
Deportivo La Coruna v Las Palmas
Girona v Levante
Eibar v Celta Vigo