0

Hello so I have been trying to fox this for a few hours now and just cant figure out what is wrong, I have made api calls in discord python before but this is the first time using multiple variables like this.

@client.command()
async def random(ctx):
    url = ('https://randomuser.me/api/')

    response = requests.get(url)
    title = response.json()["title"]
    first = response.json()["first"]
    last = response.json()["last"]
    number = response.json()["number"]
    street = response.json()["name"]
    city = response.json()["city"]
    state = response.json()["state"]
    postcode = response.json()["postcode"]
    country = response.json()["country"]
    phone = response.json()["phone"]
    age = response.json()["age"]
    dob = response.json()["date"]
    gender = response.json()["gender"]
    username = response.json()["username"]
    password = response.json()["password"]
    image = response.json()['large']

    embed = discord.Embed(title="Random Generator", description="**Name:** f'{title}, {first} {last}\n**Address:** {number} {street}, {city}, {state}, {postcode}, {country}\n**Phone:** {phone}\n**Age:** {age}, {dob}\n**Gender:** {gender}\n**Alias:** {username}, {password}\n\n**Profile Picture Link:** {large}'", color=18321)
    embed.set_footer(text="Thanks for using the bot")                                                
    embed.set_image(url="value=f'{large}'")
                                                           
    await ctx.send(embed=embed)

Please if anyone knows what is wrong and can help thank you

Ceres
  • 2,498
  • 1
  • 10
  • 28
3301
  • 23
  • 3
  • that is not an f-string, f-strings have the `f` before the string, yours i s inside with just another string quote inside the string, `f'some string'` not `"name: f'title'"` You can see by the syntax highlighting too – bherbruck Mar 03 '21 at 13:17
  • 2
    Side note, why are you calling `response.json()` so many times? it's very inefficient. Call it once and save the result: `json_response = response.json()` – DeepSpace Mar 03 '21 at 13:19
  • 1
    Also, you never define `large`. You defined `image`, so that will give you a `NameError` – astrochun Mar 03 '21 at 13:42

2 Answers2

5

f-strings cannot be used inside other strings.

Instead of doing

description="**Name:** f'..."

you should do

description=f"**Name:** {title}..."

Same with all your f-strings

Icebreaker454
  • 1,031
  • 7
  • 12
0

You can't use f-strings inside other strings like "name: f'{title}'". Try this instead:

description = f"**Name:** {title}..."
Daud
  • 296
  • 4
  • 9