[RPG] Can you get infinite spells through True Polymorph and Shapechange

dnd-5epolymorphshapeshifterspellcasting

You're a level 17+ Wizard and you cast True Polymorph on yourself to turn yourself into a CR 17 Adult Gold Dragon. This grants you the stat block of said Adult Gold Dragon, including its Change Shape ability, allowing it to assume the form of "a humanoid or beast with a Challenge Rating no higher than its own". It uses this ability to turn into a CR 12 Archmage, which has the Spellcasting feature, allowing it to cast spells using as an 18th level spellcaster, using its intelligence score.

Once they expend a number of spell slots from its new form, it proceeds to use its new 9th-level spell slot to cast True Polymorph on itself again, turning into a brand new Adult Gold Dragon form, and then using Change Shape to turn into a brand new Archmage form, and then repeats this process to gain an infinite number of spell slots.

Is there anything that prevents this from working?

I know that True Polymorph is a Concentration spell, so the first True Polymorph would end when they cast the second one, I don't think they lose the spell they're Concentrating on if they lose the Spellcasting feature that gave them the slot in the first place? 5e doesn't have any hidden rules, and there doesn't seem to be anything about it working that way in the Spellcasting chapter of the PHB – and if it did work that way, wouldn't it break Polymorph spells in general, since they lose their Spellcasting class feature while Polymorphed?

Obviously the chain gets broken if they fail a Concentration saving throw, but they'd get the Adult Gold Dragon's Legendary Resistance to help them out, there – and it'd get reset every time they True Polymorph themselves, too.

Best Answer

You would not gain the Spellcasting trait

The Ancient Gold Dragon's Change Shape ability has an additional clause (emphasis mine):

Its statistics and capabilities are otherwise replaced by those of the new form, except any class features or legendary actions of that form.

This means that you would not gain the Spellcasting trait since the "Introduction" to the Monster Manual clarifies (emphasis mine):

Spellcasting

A monster with the Spellcasting class feature has a spellcaster level and spell slots, which it uses to cast its spells of 1st level and higher (as explained in the Player’s Handbook). The spellcaster level is also used for any cantrips included in the feature.

You can find more information about what constitutes a class feature among monster traits in this Q&A: What is considered a class feature for a monster for the purpose of Change Shape?