Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions interactions/client/models/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
from asyncio import Task, get_running_loop, sleep
from functools import wraps
from typing import TYPE_CHECKING, Awaitable, Callable, Iterable, List, Optional, TypeVar, Union
from typing import (
TYPE_CHECKING,
Awaitable,
Callable,
Coroutine,
Iterable,
List,
Optional,
TypeVar,
Union,
)

from ...api.error import LibraryException
from .component import ActionRow, Button, SelectMenu
Expand Down Expand Up @@ -41,7 +51,7 @@ async def command(ctx):
:rtype:
"""

def decorator(coro: Callable[..., Awaitable]) -> Callable[..., Awaitable]:
def decorator(coro: Callable[..., Union[Awaitable, Coroutine]]) -> Callable[..., Awaitable]:
from ..context import ComponentContext

@wraps(coro)
Expand All @@ -50,7 +60,15 @@ async def deferring_func(ctx: Union["CommandContext", "ComponentContext"], *args
loop = get_running_loop()
except RuntimeError as e:
raise RuntimeError("No running event loop detected!") from e
task: Task = loop.create_task(coro(ctx, *args, **kwargs))

if isinstance(args[0], (ComponentContext, CommandContext)):
self = ctx
ctx = list(args).pop(0)

task: Task = loop.create_task(coro(self, ctx, *args, **kwargs))

else:
task: Task = loop.create_task(coro(ctx, *args, **kwargs))

await sleep(delay)

Expand Down