Assign flight mode to a channel through code?

How do I assign a custom flight mode to a transmitter channel through the code (instead of using Mission Planner or QGroundControl)? I can’t seem to find the file that assigns the flight modes to channels.

Thank you!