diff --git a/nomen/utils.py b/nomen/utils.py index 417a9c8..29a77ef 100644 --- a/nomen/utils.py +++ b/nomen/utils.py @@ -4,6 +4,7 @@ from itertools import chain import re2 as re from disnake import ChannelType +from disnake.ext.commands import BadArgument log = logging.getLogger("nomen.utils") @@ -87,9 +88,14 @@ def compile_keyword(keyword, regex): if not regex: keyword = re.escape(keyword) - reg = re.compile(rf"(?i)\b{keyword}\b") - regex_cache[(keyword, regex)] = reg - return reg + try: + reg = re.compile(rf"(?i)\b{keyword}\b") + regex_cache[(keyword, regex)] = reg + return reg + except re._re2.Error: + raise BadArgument( + "Invalid regex. Nomen only supports regexes that [re2]() can parse." + ) def contains(string, keyword, regex):