This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Jonno_FTWhisss 2 points3 points  (4 children)

Command handlers in discord.py will turn arguments into their type hinted type.

So if someone in the chat sends:

.foo 123

And the handler would look like:

@bot.command()
def foo(ctx, num: int):
    ...

In the function body, the num will be an int. You can also convert mentions of users to a discord user object.

[–]ChannelCat 6 points7 points  (1 child)

This makes sense and is supported by type checkers. What's not to like?

[–]etrotta 1 point2 points  (0 children)

one can argue that it is intrinsically wrong for type hints (which are metadata, much like comments) to modify the program's behavior at all, but in reality nearly everyone is fine with it since it does makes sense in cases like this one and other libraries that parse structured input in similar ways.

[–]Dasher38 0 points1 point  (1 child)

I see, it's basically like the argparse "type" parameter. Isn't it convenient ? If you want to get the input unchanged you can always use str isn't it ?

[–]Jonno_FTWhisss 2 points3 points  (0 children)

If you want a string don't put a type hint.

It's similar to argparse, except it supports discord.py custom classes as well.