Skip to content

Commit ac7c341

Browse files
NeloBlivionpre-commit-ci[bot]Lulalaby
authored
feat: add once kwarg to Cog.listener (#2403)
* add once kwarg to Cog.listener * clarify * style(pre-commit): auto fixes from pre-commit.com hooks --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Lala Sabathil <[email protected]>
1 parent 548ca85 commit ac7c341

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

discord/cog.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,9 @@ def _get_overridden_method(cls, method: FuncT) -> FuncT | None:
379379
)
380380

381381
@classmethod
382-
def listener(cls, name: str = MISSING) -> Callable[[FuncT], FuncT]:
382+
def listener(
383+
cls, name: str = MISSING, once: bool = False
384+
) -> Callable[[FuncT], FuncT]:
383385
"""A decorator that marks a function as a listener.
384386
385387
This is the cog equivalent of :meth:`.Bot.listen`.
@@ -389,6 +391,9 @@ def listener(cls, name: str = MISSING) -> Callable[[FuncT], FuncT]:
389391
name: :class:`str`
390392
The name of the event being listened to. If not provided, it
391393
defaults to the function's name.
394+
once: :class:`bool`
395+
If this listener should only be called once after each cog load.
396+
Defaults to false.
392397
393398
Raises
394399
------
@@ -411,6 +416,7 @@ def decorator(func: FuncT) -> FuncT:
411416
raise TypeError("Listener function must be a coroutine function.")
412417
actual.__cog_listener__ = True
413418
to_assign = name or actual.__name__
419+
actual._once = once
414420
try:
415421
actual.__cog_listener_names__.append(to_assign)
416422
except AttributeError:

0 commit comments

Comments
 (0)