Discord.py error discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: 'dict' object is not callable

This code:

    @commands.command(name="currency", aliases=['ce'])     async def currencyexchange(self, ctx, currency1, currency2, amount:str):         url = "https://www.amdoren.com/api/currency.php?api_key=WTkbre7JxKME95tsu62R2bBng42rKE&from=" + currency1 + "&to=" + currency2 + "&amount=" + amount         async with ClientSession() as session:             async with session.get(url) as response:                       r = await response.json(content_type=None)                 embed = discord.Embed(colour=discord.Colour.purple(), timestamp = ctx.message.created_at, title=f"Currency Rates")                 embed.set_footer(text=f"Requested by {ctx.author}")                 embed.add_field(name=f"Exchanged", value = f"{r('amount')}", inline = False)                 await ctx.send(embed=embed) 

returns the error shown the title. Not sure where I messed up, but I’m in need of some help.

API returns this:

{ "error" : 0, "error_message" : "-", "amount" : 6.31656 } 

Thanks

Professor Asked on October 18, 2020 in Android langue,   Python.
Add Comment
1 Answer(s)

    On this line:

    embed.add_field(name=f"Exchanged", value = f"{r('amount')}", inline = False) 

    When you write r('amount'), with parentheses it’s treating r like a function. In order to get the value of the amount field from r you need to use square brackets. It would look like this:

    embed.add_field(name=f"Exchanged", value = f"{r['amount']}", inline = False) 
    Professor Answered on October 18, 2020.
    Add Comment

    Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.