I’m trying to make a crypto command but its giving me an error.I tried doing everything i can’t seem to fix it. If anyone fixes it please mention how you fixed it i need to learn how cause i get these errors very frequently.
This is the code:
@client.command(pass_context=True)
async def ethprice(ctx):
response = requests.get('https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD')
json_data = json.loads(response.text)
price = json_data['USD']
await ctx.send("Etherium price is: $" + price)
TypeError: can only concatenate str (not "float") to str
If anyone can help me i’d appriciate it 🙂
>Solution :
Your price variable is a float. You simply need to convert it to a string before using the + operator.
@client.command(pass_context=True)
async def ethprice(ctx):
response = requests.get('https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD')
json_data = json.loads(response.text)
price = json_data['USD']
await ctx.send("Etherium price is: $" + str(price))