Skip to content

Commit

Permalink
[commands] add default __repr__ for CustomDefault
Browse files Browse the repository at this point in the history
With this change CustomDefaults display nicer in help commands and
in command.signature
  • Loading branch information
thecaralice authored and khazhyk committed Jun 24, 2019
1 parent 316eb45 commit a266a02
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
14 changes: 13 additions & 1 deletion discord/ext/commands/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,19 @@
'Call',
)

class CustomDefault:
class CustomDefaultMeta(type):
def __new__(cls, *args, **kwargs):
name, bases, attrs = args
attrs['display'] = kwargs.pop('display', name)
return super().__new__(cls, name, bases, attrs, **kwargs)

def __repr__(cls):
return str(cls)

def __str__(cls):
return cls.display

class CustomDefault(metaclass=CustomDefaultMeta):
"""The base class of custom defaults that require the :class:`.Context`.
Classes that derive from this should override the :meth:`~.CustomDefault.default`
Expand Down
4 changes: 4 additions & 0 deletions docs/ext/commands/commands.rst
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,10 @@ A DefaultParam returning ``None`` is valid - if this should be an error, raise :
my_bytes = io.BytesIO(await resp.content.read())
await ctx.send(file=discord.File(filename="your_image", fp=my_bytes))
.. tip:: You can change the name of a Custom Default that is displayed in help command by passing ``display`` meta option. Using previous example: ``class LastImage(CustomDefault, display='last image from chat')``




Checks
-------
Expand Down

0 comments on commit a266a02

Please sign in to comment.