diff --git a/flask_discord/utils.py b/flask_discord/utils.py index 9b4a75a..96056a3 100644 --- a/flask_discord/utils.py +++ b/flask_discord/utils.py @@ -4,6 +4,7 @@ from . import exceptions from flask import current_app +import asyncio class JSONBool(object): @@ -41,11 +42,18 @@ def requires_authorization(view): """ # TODO: Add support to validate scopes. - - @functools.wraps(view) - def wrapper(*args, **kwargs): - if not current_app.discord.authorized: - raise exceptions.Unauthorized - return view(*args, **kwargs) - - return wrapper + if asyncio.iscoroutinefunction(view): + + @functools.wraps(view) + async def wrapper(*args, **kwargs): + if not current_app.discord.authorized: + raise exceptions.Unauthorized + return await view(*args, **kwargs) + return wrapper + else: + @functools.wraps(view) + def wrapper(*args, **kwargs): + if not current_app.discord.authorized: + raise exceptions.Unauthorized + return view(*args, **kwargs) + return wrapper