UPDATE: this exploit was patched out of the console versions of the game in the 1.3 patch. If you're trying to use the same codes and are having problems with repeating an animal name, try changing the order of the codes or adding a number/letter on the end and that should allow it to go through. It's best to buy a chicken for this, and use the code(s) when naming it to get specific item(s) you really need. You can also utilise this Stardew Valley cheat when it comes to purchasing and naming an animal, but you only get the item(s) once. If you want to speed up this process further, go and chat to Gus the bartender at the saloon as he regularly mentions your name. For example, naming yourself will mean that whenever the game references your name you'll receive a Legend fish, Treasure Chest, and Stardrop in your inventory which can be sold for 5,000g, 5,000g, and 7,777g respectively, although the Stardrop is often consumed automatically rather than remaining in your inventory to sell.
When it comes to Stardew Valley cheats, this is the big one! Every item in the game has a unique numerical code, and by using up to three of these codes each in as your character name, you'll spawn those items in your inventory every time your name is mentioned in the game. I had to restart my game twice one day for different reasons and since it was good luck I went to the casino all 3 times I replayed that day, started with 1000, just kept betting 100 and got 3 stardrops every time sooner or later and ended up with a few hundred thousand coins.