Crypto command, SLP

Asked Jul 10, 2021·5 replies·Last activity 5 years ago·Open in Discord ↗
Archived from the original community forum
Things may have changed since it was written. Still stuck? Ask the community on Discord.

5 replies

@Marble Crab 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

Hey @Maple Goose!

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 @Marble Crab!

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.

Polar Cat said:
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.

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

Didn't find your answer? The community is on Discord.

Ask on Discord