Although there isn't discount code functionality on event forms or membership forms, you can create a second page with a separate form for discounts. This page can have different prices than the main page. Then refer users who are eligible for the discount to go to this other page.