Skip to content

Commit b8733f2

Browse files
authored
fix attribute error
Signed-off-by: Om <92863779+Om1609@users.noreply.github.com>
1 parent 2e9ab61 commit b8733f2

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

discord/client.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ def _check(*args):
11471147
return asyncio.wait_for(future, timeout)
11481148

11491149
# event registration
1150-
def add_listener(self, func: Coro, name: str = MISSING) -> None:
1150+
def add_listener(self, func: Coro, name: str = MISSING, once: bool = False) -> None:
11511151
"""The non decorator alternative to :meth:`.listen`.
11521152
11531153
Parameters
@@ -1176,6 +1176,7 @@ async def my_message(message): pass
11761176
client.add_listener(my_message, 'on_message')
11771177
"""
11781178
name = func.__name__ if name is MISSING else name
1179+
func._once = once
11791180

11801181
if not name.startswith("on_"):
11811182
raise ValueError("The 'name' parameter must start with 'on_'")
@@ -1189,9 +1190,11 @@ async def my_message(message): pass
11891190
self._event_handlers[name] = [func]
11901191

11911192
_log.debug(
1192-
"%s has successfully been registered as a handler for event %s",
1193+
"%s has successfully been registered as a handler for event %s with once %s",
11931194
func.__name__,
11941195
name,
1196+
once
1197+
11951198
)
11961199

11971200
def remove_listener(self, func: Coro, name: str = MISSING) -> None:
@@ -1256,8 +1259,7 @@ def decorator(func: Coro) -> Coro:
12561259
if name == "on_application_command_error":
12571260
return self.event(func)
12581261

1259-
func._once = once
1260-
self.add_listener(func, name)
1262+
self.add_listener(func, name, once)
12611263
return func
12621264

12631265
if asyncio.iscoroutinefunction(name):

0 commit comments

Comments
 (0)