Now this is not exactly what you need, but you can adapt it to work with your game. There is a guide on admin commands where you can learn to make your own admin commands. Now, you could just adapt it by replacing some of the code such as the IsAdmin() function with nothing, or you could add something where you have to check if the player has enough “Magic” or something like that before running the command. Then you just trigger a function for each command/spell and it acts as if you are casting a spell.
Here is the tutorial on that if your interested: How to make basic admin commands