-
-
Notifications
You must be signed in to change notification settings - Fork 480
Closed
Labels
Milestone
Description
Summary
subcommand can no longer be registered in classes
Reproduction Steps
See minimal reproducible code below.
Minimal Reproducible Code
from discord import ApplicationContext
from discord.ext import commands
class SampleGroupClass:
def __init__(self, num: int):
self.group = bot.create_group("sample", "Sample Description")
self.num = num
# call the decorator manually
self.group.command(name="getnum")(self.sample_callback)
async def sample_callback(self, ctx: ApplicationContext):
await ctx.respond(str(self.num))
async def on_ready():
print("Connected")
await bot.sync_commands()
print("Synced")
if __name__ == "__main__":
bot = commands.Bot()
sample = SampleGroupClass(3)
bot.add_listener(on_ready)
bot.run("")Expected Results
Prior to commit 6913833c1e076b9c14e7a51ceeb1ff4c156e9164 you could register subcommands inside classes by manually invoking the decorator. However, this update means there is no longer a way to register subcommands inside classes.
Actual Results
Traceback (most recent call last):
File "/home/unrealintegers/Code/EYES/venv/lib/python3.9/site-packages/discord/commands/core.py", line 668, in _check_required_params
next(params)
StopIteration
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/unrealintegers/.config/JetBrains/PyCharmCE2021.2/scratches/scratch_4.py", line 25, in <module>
sample = SampleGroupClass(3)
File "/home/unrealintegers/.config/JetBrains/PyCharmCE2021.2/scratches/scratch_4.py", line 11, in __init__
self.group.command(name="getnum")(self.sample_callback)
File "/home/unrealintegers/Code/EYES/venv/lib/python3.9/site-packages/discord/commands/core.py", line 1041, in wrap
command = SlashCommand(func, parent=self, **kwargs)
File "/home/unrealintegers/Code/EYES/venv/lib/python3.9/site-packages/discord/commands/core.py", line 644, in __init__
self.options: List[Option] = self._parse_options(params)
File "/home/unrealintegers/Code/EYES/venv/lib/python3.9/site-packages/discord/commands/core.py", line 676, in _parse_options
params = self._check_required_params(params)
File "/home/unrealintegers/Code/EYES/venv/lib/python3.9/site-packages/discord/commands/core.py", line 670, in _check_required_params
raise ClientException(f'Callback for {self.name} command is missing "{p}" parameter.')
discord.errors.ClientException: Callback for getnum command is missing "context" parameter.
Intents
All
System Information
- Python v3.9.7-final
- py-cord v2.0.0-candidate
- py-cord pkg_resources: v2.0.0rc1
- aiohttp v3.8.1
- system info: Linux 5.17.5-76051705-generic #202204271406
165150484021.10~63e51bd SMP PREEMPT Mon May 2 15:
Checklist
- I have searched the open issues for duplicates.
- I have shown the entire traceback, if possible.
- I have removed my token from display, if visible.
Additional Context
The error arises since when a class method is used in its own class, the self parameter is omitted.
TollyH
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done