#Creating custom converter

1 messages · Page 1 of 1 (latest)

bronze kestrel
#

Hello i was wonderig if disnake supports custom converters for commands. For example i would like to have custom converter for date input instead of always doing it manually in command. Are there any examples if it is supported? Do i just inherit from commands.Converter and add my logic and it should work?

candid tinsel
#

commands.Converter in general is basically incompatible with proper type-hinting, it's not supported in slash commands - you can provide a converter function like date: datetime = commands.Param(converter=str_to_datetime), or register one globally by doing something along these lines:

@commands.register_injection
def str_to_datetime(inter, date_input: str) -> datetime:
    return ...

# then:
@commands.slash_command
async def my_cmd(inter, date: datetime):
    ...
bronze kestrel
candid tinsel
#

yup, based on the return type annotation

bronze kestrel
#

oh okay then thanks tip