Can I make the BT module disconnect with a BT module and connect with another in the code?
Send AT+ROLE=1 to BT module to set module into master role.
To set module back to slave mode, send AT+ROLE=0

Also check this video, you have source code in the description. It will help you understand how to do it.