Instead of rejecting the discount code, have the discount code do nothing on its own. Use the existence of the discount code as something to trigger your custom code in the Shopify Scripts to run. Shopfiy Scripts can detect if a code was added and what that code is.
That Shopify Script could - in theory - then opt to discount some items and opt to not discount others. Depending on complexity of discounts this may be a crazy idea.