Discord.py: Command line style arguments

Created on 10 May 2020  路  7Comments  路  Source: Rapptz/discord.py

The Problem

Sometimes commands with more complex arguments can be hard to use, especially ones with option/default arguments. If you wanted a command with multiple arguments, all of which being optional, and you wanted to specify a value for only the last one...

The Current Solution

...you would have to move that argument to be the first one. But then if any of the arguments could be the selected one, you would need some kind of none value, making the command much more annoying to use. You could make a custom converter and using something like Greedy, but if you are just taking in text, this wouldn't work. You would probably have to parse the string yourself.

The Ideal Solution

Having some kind of way to have command line style arguments for commands (e.g. --argument value or -flag) could help make these commands easier to use.

Summary

A way to either have specific or all of your arguments to a Command be a command line style argument.

Most helpful comment

You can parse the flags yourselves. That's what "command line" programs do.

All 7 comments

You can parse the flags yourselves. That's what "command line" programs do.

A solution to this would be to use ext.flags which is an external extension for discord.py. It uses argparse to parse arguments and seems to fit your use case.

I got linked to it after I opened this issue but I think it makes sense for there to be something built in. Danny said he had an idea but it doesn't sound like it will be happening any time in the future. Not sure if this means this issue should be closed as a won't fix or kept open to track the idea.

the problem i had with greedy is if we have this command:

async def inc_exc(ctx, include: commands.Greedy[discord.Member], 
                       serperator: typing.Optional[str],
                       exclude:  commands.Greedy[discord.Member]):

then in cases like : !inc_exc @person1 @person2 not @person3 then the code would say include = [@person1], serperator = "@person2 not @person3 and then exclude = []. I would expect that include = [@person1, @person2], seperator = "not", and exclude = [@person3]
It would be good if greedy actually worked in these situations too compared to obviously not working.
I know in the documentation it says that greedy and typing optional have problems with strings, and thats understandable as all commands are strings but I think that it would be nice if greedy was actually greedy as this situation proves that there are cases where it falls down. funnily enough if you remove the @person3 from the command it does work as intended with include having all the members, separator is not and exclude is an empty list.

currently, i parse it myself but it would be nice if discord.py could do that for me.

@14ROVI That's not related to this issue

@nihaals sorry I didn't want to make a new issue because it didn't seem a big enough deal and this problem was to do with greedy and optional stuff so I thought to put it here. Should I make a new issue for this or is it not worth it?

You can make your own as a feature request if you want, I'm not sure if it will get implemented

Was this page helpful?
0 / 5 - 0 ratings

Related issues

TunaHobby picture TunaHobby  路  3Comments

synbitz picture synbitz  路  3Comments

jzburda picture jzburda  路  3Comments

adhoc92 picture adhoc92  路  3Comments

Be4Vision picture Be4Vision  路  3Comments