aboutsummaryrefslogtreecommitdiff
path: root/discord/enums.py
diff options
context:
space:
mode:
Diffstat (limited to 'discord/enums.py')
-rw-r--r--discord/enums.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/discord/enums.py b/discord/enums.py
index 10a7f60b..1ae7faf6 100644
--- a/discord/enums.py
+++ b/discord/enums.py
@@ -73,3 +73,13 @@ class DefaultAvatar(Enum):
def __str__(self):
return self.name
+
+def try_enum(cls, val):
+ """A function that tries to turn the value into enum ``cls``.
+
+ If it fails it returns the value instead.
+ """
+ try:
+ return cls(val)
+ except ValueError:
+ return val