No. Ben Affleck does not appear in The Dark Knight (2008) in any capacity—no cameo, no Easter egg, no credit.
The confusion arises because Affleck later played Batman/Bruce Wayne in the DC Extended Universe (Batman v Superman, Suicide Squad, Justice League, The Flash). But in 2008, Christian Bale was the Dark Knight, and Affleck was directing Gone Baby Gone and acting in The Company Men.
No shared universe connected them at the time.