M
M
Mem13882021-06-07 07:48:49
Python
Mem1388, 2021-06-07 07:48:49

How to pass a JSON dictionary as an argument?

If passed through a regular string, the discord complains about quotes, so now it is passed as literal_eval.
But if you pass it through literal_eval, you need to escape all quotes and \n..
Is it possible to somehow pass a dictionary so that the quotes do not need to be escaped, but the dictionary itself is also passed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Nevzorov, 2021-06-09
@Mem1388

Use json.loads function as converter and keyword-only arguments

from json import loads

@commands.command()
@commands.is_owner()
async def test(ctx, *, j: loads):
    await ctx.send(f"{type(j)}\n{j}")

qEmEqPn.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question