M
M
Mem13882021-06-21 04:25:11
Python
Mem1388, 2021-06-21 04:25:11

How to ignore quotes in an argument?

If you pass an argument like this:

async def test(ctx, *, arg):
    ...

Then the quotes will be ignored, but if there is another parameter before arg, the discord complains about the quotes. How to fix it?
async def testemb(self, ctx, channel: Optional[discord.TextChannel], *, arg: str):
    try:
        if channel is None:
            my_json = arg
            if "plainText" in my_json:
                emb = discord.Embed.from_dict(my_json)
                plainText = my_json['plainText']
                await ctx.send(plainText, embed = emb)
            else:
                emb = discord.Embed.from_dict(my_json)
                await ctx.send(embed = emb)
        else:
            my_json = arg
            if "plainText" in my_json:
                emb = discord.Embed.from_dict(my_json)
                plainText = my_json['plainText']
                await channel.send(plainText, embed = emb)
            else:
                emb = discord.Embed.from_dict(my_json)
                await channel.send(embed = emb)
    except Exception as e:
        print(e)
        my_json = arg
        emb = discord.Embed(description = f'{arg}', color = 0xdb7dbc)
        await ctx.send(embed = emb)

discord.ext.commands.errors.UnexpectedQuoteError: Unexpected quote mark, '"', in non-quoted string

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2021-06-21
@LazyTalent

async def test(ctx, *, arg):
You can't do that because * must be followed by named arguments only: PEP 3102

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question