The truth of the matter is, Spike didn't realize that writing The Noble Dragon Code would get him worshipped as a god but, hey, whattcha gonna do? Them's the breaks.
When Discord hears that his own creation, poison joke, continues to flourish in the Everfree, he simply cannot resist a good prank. Poison joke in hand, he storms Canterlot Castle.