Skip to content
This repository was archived by the owner on Dec 26, 2021. It is now read-only.

Commit b4b586d

Browse files
committed
Cog attrs: slash_commands, user_commands, message_commands
1 parent 9f15821 commit b4b586d

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

dislash/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "1.4.7"
1+
__version__ = "1.4.8"
22

33

44
from .interactions import *

dislash/application_commands/slash_client.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -942,19 +942,36 @@ def _error_handler_exists(self, handler_name):
942942
)
943943

944944
def _inject_cogs(self, cog):
945-
for cmd in self.commands.values():
945+
# Insert the cog into slash commands:
946+
if not hasattr(cog, "slash_commands"):
947+
cog.slash_commands = []
948+
for cmd in self.slash_commands.values():
949+
if cmd._cog_class_name == cog.__class__.__name__:
950+
cmd._inject_cog(cog)
951+
cog.slash_commands.append(cmd)
952+
# Insert the cog into user commands:
953+
if not hasattr(cog, "user_commands"):
954+
cog.user_commands = []
955+
for cmd in self.user_commands.values():
946956
if cmd._cog_class_name == cog.__class__.__name__:
947957
cmd._inject_cog(cog)
958+
cog.user_commands.append(cmd)
959+
# Insert the cog into message commands:
960+
if not hasattr(cog, "message_commands"):
961+
cog.message_commands = []
962+
for cmd in self.message_commands.values():
963+
if cmd._cog_class_name == cog.__class__.__name__:
964+
cmd._inject_cog(cog)
965+
cog.message_commands.append(cmd)
966+
# Auto register the commands again
948967
if self.is_ready:
949968
self.client.loop.create_task(self._auto_register_or_patch())
950969
# We need to know which cogs are able to dispatch errors
951970
pairs = cog.get_listeners()
952-
for name, func in pairs:
953-
# Loop through all error listener types
954-
for event_name, cog_names in self._cogs_with_err_listeners.items():
955-
if name == event_name:
956-
cog_names.append(cog.qualified_name)
957-
break
971+
for event_name, func in pairs:
972+
cog_names = self._cogs_with_err_listeners.get(event_name)
973+
if cog_names is not None:
974+
cog_names.append(cog.qualified_name)
958975

959976
def _eject_cogs(self, name):
960977
for cog_names in self._cogs_with_err_listeners.values():

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
author_email='[email protected]',
2222
keywords='python, discord, slash, commands, api, discord-api, discord-py, slash-commands, message-components, buttons, select-menus, context-menus',
2323
packages=['dislash', 'dislash.application_commands', 'dislash.interactions', 'dislash.application_commands._modifications'],
24-
python_requires='>=3.8, <4',
24+
python_requires='>=3.6, <4',
2525
install_requires=requirements,
2626
project_urls={
2727
'Documentation': 'https://dislashpy.readthedocs.io/en/latest',
@@ -33,6 +33,8 @@
3333
'Intended Audience :: Developers',
3434
'Natural Language :: English',
3535
'Operating System :: OS Independent',
36+
'Programming Language :: Python :: 3.6',
37+
'Programming Language :: Python :: 3.7',
3638
'Programming Language :: Python :: 3.8',
3739
'Programming Language :: Python :: 3.9',
3840
'Topic :: Internet',

0 commit comments

Comments
 (0)