Here's the minimal example
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amssymb}
\newcommand{\bbE}[1][X]{\mathbb{E}\left[#1\right]}
\begin{document}
Working:
$\bbE[XY]$
Broken:
$\bbE[\bbE[X]] \bbE[\bbE[Y]]$
\end{document}
When I run this I get the following error:
Missing delimiter (. inserted).


\bbE[{\bbE[X]}]. But you don't need (and likely shouldn't) use\left...\rightfor single symbols likeXandY, so you could simplify your command to\newcommand{\bbE}{\mathbb{E}}– Phelype Oleinik Feb 10 '21 at 14:06\left...\rightfor single symbols? when I actually use this I have expectations of sums and larger things – reuzed Feb 10 '21 at 17:42$x(1+2)x$with$x\left(1+2\right)x$. Also\left...\rightencloses the subformula in a box, so line breaking can't happen if needed. See here. Regardless, that's best practices but not what's causing you the error. The error is due to how LaTeX grabs the optional argument, and adding braces like in\bbE[{\bbE[X]}]does solve the problem (which is what the post campa linked says) – Phelype Oleinik Feb 10 '21 at 17:54\NewDocumentCommand\bbE{O{X}}{\mathbb{E}\left[#1\right]}. Commands defined with\NewDocumentCommandauto-match the delimiters, so you can nest them – Phelype Oleinik Feb 10 '21 at 18:05