I have the code:
# Random Choice
@client.command(aliases=["rand_c"])
async def random_choice(ctx, python_list):
list_1 = random.choice(python_list)
await ctx.send(list_1)
"m." is my prefix
But, the output after typing "m.rand_c ["Cats", "Dogs"]":
discord.ext.commands.errors.UnexpectedQuoteError: Unexpected quote mark, '"', in non-quoted string
I think this is a bug since it works fine in regular Python.
This is because of how discord.py's commands extension works to discern arguments. Quotes are used to specify a multi-word string in a single argument, as spaces are used to separate arguments typically.
Luckily, there's another way to do this, and it'd actually make things easier for the end user as they would not have to manually construct a list. Take a look at the 'choose' command in the example bot here. The asterisk allows the 'choices' arg to accept multiple space-separated words.
I prefer to do it in list form @gogurtenjoyer, how do I do that?
You do not - as I said, quotes are used for special purpose in the commands extension. Please continue this discussion on the server, as this is a usage question and not a bug with the library. Thanks!
Using eval on untrusted input is never a good idea so that solution is subpar, especially since constructed input can cause your interpreter to crash with a segfault even if using literal_eval. Note that the proper solution was already given to you -- whether you accept it or not is ultimately up to you but the way mentioned is the way to do it.
Most helpful comment
Using eval on untrusted input is never a good idea so that solution is subpar, especially since constructed input can cause your interpreter to crash with a segfault even if using
literal_eval. Note that the proper solution was already given to you -- whether you accept it or not is ultimately up to you but the way mentioned is the way to do it.