Skip to content

Commit 03f0a25

Browse files
committed
Fixed cog not working properly
1 parent cd31c89 commit 03f0a25

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

discord_slash/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def get_cog_commands(self, cog: commands.Cog):
6565
res = [x for x in func_list if
6666
isinstance(x, model.CogCommandObject) or isinstance(x, model.CogSubcommandObject)]
6767
for x in res:
68+
x.cog = cog
6869
if isinstance(x, model.CogCommandObject):
6970
self.commands[x.name] = x
7071
else:

discord_slash/model.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,31 +173,45 @@ async def delete(self, message_id: typing.Union[int, str] = "@original"):
173173
class CommandObject:
174174
def __init__(self, name, cmd, *subcommands): # Let's reuse old command formatting.
175175
self.name = name
176-
self.invoke = cmd["func"]
176+
self.func = cmd["func"]
177177
self.description = cmd["description"]
178178
self.auto_convert = cmd["auto_convert"]
179179
self.allowed_guild_ids = cmd["guild_ids"]
180180
self.options = cmd["api_options"]
181181
self.has_subcommands = cmd["has_subcommands"]
182182
self.subcommands = subcommands
183183

184+
def invoke(self, *args):
185+
return self.func(*args)
186+
184187

185188
class SubcommandObject:
186189
def __init__(self, sub, base, name, sub_group=None):
187190
self.base = base
188191
self.subcommand_group = sub_group
189192
self.name = name
190-
self.invoke = sub["func"]
193+
self.func = sub["func"]
191194
self.description = sub["description"]
192195
self.auto_convert = sub["auto_convert"]
193196
self.allowed_guild_ids = sub["guild_ids"]
194197

198+
def invoke(self, *args):
199+
return self.func(*args)
200+
195201

196202
class CogCommandObject(CommandObject):
197203
def __init__(self, *args):
198204
super().__init__(*args)
205+
self.cog = None # Manually set this later.
206+
207+
def invoke(self, *args):
208+
return self.func(self.cog, *args)
199209

200210

201211
class CogSubcommandObject(SubcommandObject):
202212
def __init__(self, *args):
203213
super().__init__(*args)
214+
self.cog = None # Manually set this later.
215+
216+
def invoke(self, *args):
217+
return self.func(self.cog, *args)

0 commit comments

Comments
 (0)