Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error when app_commands.Group misses a name #9581

Merged
merged 1 commit into from
Sep 28, 2023
Merged

Fix error when app_commands.Group misses a name #9581

merged 1 commit into from
Sep 28, 2023

Conversation

itswilliboy
Copy link
Contributor

@itswilliboy itswilliboy commented Sep 27, 2023

Summary

When creating a slash group through this syntax:

group = app_commands.Group(name="group")

TypeError will be raised, indicating that the group misses a description.

Traceback
Traceback (most recent call last):
  File "C:\Users\User\Desktop\testty\main.py", line 26, in
    class Cog(commands.Cog):
  File "C:\Users\User\Desktop\testty\main.py", line 27, in Cog
    group = app_commands.Group(name="a")
  File "C:\Users\User\Desktop\testty\.venv\lib\site-packages\discord\app_commands\commands.py", line 1549, in __init__
    raise TypeError('groups must have a description')
TypeError: groups must have a description


group = app_commands.Group(description="description")

This instead raises an error when trying to encode the name while syncing, which is MISSING:

Traceback (most recent call last):
  File "C:\Users\User\Desktop\testty\.venv\lib\site-packages\discord\client.py", line 441, in _run_event
    await coro(*args, **kwargs)
  File "C:\Users\User\Desktop\testty\main.py", line 22, in on_message
    synced = await bot.tree.sync()
  File "C:\Users\User\Desktop\testty\.venv\lib\site-packages\discord\app_commands\tree.py", line 1067, in sync
    data = await self._http.bulk_upsert_global_commands(self.client.application_id, payload=payload)
  File "C:\Users\User\Desktop\testty\.venv\lib\site-packages\discord\http.py", line 587, in request
    kwargs['data'] = utils._to_json(kwargs.pop('json'))
  File "C:\Users\User\Desktop\testty\.venv\lib\site-packages\discord\utils.py", line 650, in _to_json
    return json.dumps(obj, separators=(',', ':'), ensure_ascii=True)
  File "c:\users\User\appdata\local\programs\python\python310\lib\json\__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "c:\users\User\appdata\local\programs\python\python310\lib\json\encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "c:\users\User\appdata\local\programs\python\python310\lib\json\encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "c:\users\User\appdata\local\programs\python\python310\lib\json\encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type _MissingSentinel is not JSON serializable

The intended behaviour is for the name to be the class name when subclassing app_commands.Group, but since this isn't a subclass, it doesn't work.

This PR proposes to raise an error similar to the "missing description" one. This should not impact the creation of slash groups in any way while creating them through subclassing since the name is already set to the class name.

Checklist

  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed)
  • This PR is not a code change (e.g. documentation, README, ...)

@Rapptz Rapptz merged commit 5559403 into Rapptz:master Sep 28, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants