if you only want spells you know, then you can GetSpellLink("spellname") to get the spell link, then the spellID can get pulled from that.
Code:
local spellLink = GetSpellLink(spellName)
if spellLink then
local spellID = spellLink.match("spell:(%d+)")
print(spellID)
end
should work