Browse Source

[commands] Add support for stacking Cog.listener decorator.

Fix #1926
pull/1940/head
Rapptz 6 years ago
parent
commit
757584e651
  1. 9
      discord/ext/commands/cog.py

9
discord/ext/commands/cog.py

@ -102,7 +102,8 @@ class CogMeta(type):
except AttributeError: except AttributeError:
continue continue
else: else:
listeners.append((value.__cog_listener_name__, value.__name__)) for name in value.__cog_listener_names__:
listeners.append((name, value.__name__))
attrs['__cog_commands__'] = commands # this will be copied in Cog.__new__ attrs['__cog_commands__'] = commands # this will be copied in Cog.__new__
attrs['__cog_listeners__'] = tuple(listeners) attrs['__cog_listeners__'] = tuple(listeners)
@ -209,7 +210,11 @@ class Cog(metaclass=CogMeta):
if not inspect.iscoroutinefunction(func): if not inspect.iscoroutinefunction(func):
raise TypeError('Listener function must be a coroutine function.') raise TypeError('Listener function must be a coroutine function.')
func.__cog_listener__ = True func.__cog_listener__ = True
func.__cog_listener_name__ = name or func.__name__ to_assign = name or func.__name__
try:
func.__cog_listener_names__.append(to_assign)
except AttributeError:
func.__cog_listener_names__ = [to_assign]
return func return func
return decorator return decorator

Loading…
Cancel
Save