Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/1488.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix ColourConverter.convert to reject non-Color returns.
15 changes: 12 additions & 3 deletions disnake/ext/commands/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,6 @@ async def convert(self, ctx: AnyContext, argument: str) -> disnake.Color:

if argument[0:2] == "0x":
rest = argument[2:]
# Legacy backwards compatible syntax
if rest.startswith("#"):
return self.parse_hex_number(rest[1:])
return self.parse_hex_number(rest)
Expand All @@ -752,9 +751,19 @@ async def convert(self, ctx: AnyContext, argument: str) -> disnake.Color:

arg = arg.replace(" ", "_")
method = getattr(disnake.Colour, arg, None)
if arg.startswith("from_") or method is None or not inspect.ismethod(method):

if arg.startswith("from_") or method is None or not callable(method):
raise BadColourArgument(arg)
return method()

result = method()

if not isinstance(result, disnake.Color):
error_msg = (
f"The colour method '{argument}' returned an invalid type: {type(result).__name__}"
)
raise BadColourArgument(error_msg)

return result


ColorConverter = ColourConverter
Expand Down