Crypto command, SLP

hi i have this api: https://api.coingecko.com/api/v3/simple/price?ids=smooth-love-potion&vs_currencies=usd&include_market_cap=false&include_24hr_vol=false&include_24hr_change=false&include_last_updated_at=false and i want nightbot to respond: “Precio SLP: current value”. Right now it responds {“smooth-love-potion”:{“usd”:0.252183}} and i dont know how to fix it. Thanks :slight_smile:

@Jota Hiya, use $(eval) to evaluate such JSON data.

!commands add -cd=5 !slp $(eval data=$(urlfetch json https://api.coingecko.com/api/v3/simple/price?ids=smooth-love-potion&vs_currencies=usd&include_market_cap=false&include_24hr_vol=false&include_24hr_change=false&include_last_updated_at=false); `Precio SLP: ` + data.smooth-love-potion.usd)

If didn’t worked let me know

it didn’t work :frowning:
4acaa09b7c59f82c664083c87dbc08f3

Hey @Ritik_Ranjan!

Your code doesn’t work because JavaScript considers the following as an operation: smooth-love-potion.
It’s one of the subtleties of the language, it tries to subtract love from smooth, and it’ll then try to subtract potion to the previous operation, it doesn’t consider that text to be a key of the object, to fix that we use the bracket notation.


Hey @Jota!

Here’s the fix:

!addcom !slp $(eval value=$(urlfetch json https://api.coingecko.com/api/v3/simple/price?ids=smooth-love-potion&vs_currencies=usd)["smooth-love-potion"].usd; `Precio SLP: ${value}`)

Btw, you can use a simpler/shorter URL for the same result, I just removed what was false as it’s the default state.

2 Likes

thank you so much!, thank you both

2 Likes

Make sense, I will take care of it. Somewhere I was aware of it. I don’t know how I ignore. Uff

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.