I have a problem with creating a command to load information about the Bitcoin price.
Error in console: discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: can only concatenate str (not "float") to str
Here is the code:
@client.command(pass_context=True)
async def bitcoin(ctx):
url = 'http://api.coinlayer.com/live?access_key='
async with aiohttp.ClientSession() as session:
raw_response = await session.get(url)
response = await raw_response.text()
response = json.loads(response)
await ctx.send("Bitcoin price is: $" + response['rates']['BTC'])
How can I fix it?
Most likely your response['rates']['BTC']
is a float and therefore you can not directly concat it to a string using the +
User str()
to convert it to str or use f-strings f"Bitcoin price is: $ {response['rates']['BTC']}"
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments