Discord has harsh rate-limits in place at updating/modifying/removing existing application commands. Since you loop through every command and send one api request per command you get easily rate-limited very fast.
To fix this behaviour update your code as follows:
Do not clear old commands, you can just override them and the old ones will be gone.
If you want to clear all commands you can either collect them all in an array before sending the api request, or - and this is the better behaviour - just put an empty array.