Search code examples
pythonpython-3.xdiscorddiscord.py

How to fix spaces when using website requests in py?


I'm trying to make a command as always but i cannot use them with a space in between. This is my code at the moment.

@client.command()
async def cautionsign(ctx, msg):
  embed = discord.Embed(title="Here's your caution sign!")
  embed.set_image(url=f"https://api.popcat.xyz/caution?text={msg}")
  await ctx.send(embed=embed)

For ex if i use

!cautionsign test

it will show a cautionsign with test on it but if i use

!cautionsign test test

it will just show test.

If anyone can help me i'd appreciate it :)


Solution

  • try using the urllib.parse.quote to properly escape url components. For example...

    from urllib.parse import quote
    embed.set_image(url=f"https://api.popcat.xyz/caution?text={quote(msg)}")