[Addon] WoW: CastSpellByID / CastSpellByName

Hello! :slight_smile:

I started developing an addon and I have encounter an issue. (Wotlk Classic)

The addon is able to cast the spell of mounts owned by the user.
The user can store his flying and ground mount and with a simple macro:
“/ms mount” the addon checks if the flying can be done or not (it also checks if possible to use fly in Dalaran), then it casts the spell.

With Druid forms, it is an actual spell and it is protected, I have read the documentation and tried to do like a button using the secure template but no luck… (Example)

function DebugCastSwiftFlightForm(spellName)
    print("Druid Casting")
    local btn = CreateFrame("Button", "FlightForm", UIParent, "SecureActionButtonTemplate")
    
    -- Set the spell to Flight Form
    btn:SetAttribute("type", "spell")
    btn:SetAttribute("spell", spellName)
    
    -- Perform the click (You might want to customize the click depending on the situation)
    btn:Click("LeftButton")
    
end

This function works with any of the mounts, but not with the Druid forms.
With Paladins, the mount is available in the new mounts journal so It actually works.

Anyone could help me find information or an example to implement a secure way to cast the flying forms of a druid?

Thank you!

P.S. Here you can have a look at the code (it is my first addon, please forgive me):

github .com/ravelaso/MountSwitcher