Browse Source

[commands] Fix displayed_default for callables and None values

pull/9499/head
Rapptz 2 years ago
parent
commit
270fa5f2e0
  1. 2
      discord/ext/commands/core.py
  2. 8
      discord/ext/commands/parameters.py

2
discord/ext/commands/core.py

@ -1209,7 +1209,7 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
if not param.required:
# We don't want None or '' to trigger the [name=value] case and instead it should
# do [name] since [name=None] or [name=] are not exactly useful for the user.
if param.default is not None and param.displayed_default:
if param.displayed_default:
result.append(
f'[{name}={param.displayed_default}]' if not greedy else f'[{name}={param.displayed_default}]...'
)

8
discord/ext/commands/parameters.py

@ -175,7 +175,13 @@ class Parameter(inspect.Parameter):
if self._displayed_default is not empty:
return self._displayed_default
return None if self.required else str(self.default)
if self.required:
return None
if callable(self.default) or self.default is None:
return None
return str(self.default)
@property
def displayed_name(self) -> Optional[str]:

Loading…
Cancel
Save