Queries in an editing command

Asked Jan 26, 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.

So i want to be able to add a second $(query) to a command based on a query... so i have

!addcom !leaderboard Current Leaderboard :
!addcom !setleaderboard -a=!commands edit !leaderboard Current Leaderboard: $(query)

And that works fine but i'd like to see if i could add a query to the !leaderboard command without having to add it to the !setleaderboard command. The variables $(1) and $(2) could be used in the "set" command however id like to be able to check anyone's status in the posted leaderboard link without having it be preset. Is there any work around to this?

5 replies

Hey @Loyal Octopus!

Yes, there's a workaround, it's to use a Pastebin.

So for example you want your !leaderboard command's response to be:

Current leaderboard: blablabla $(query)

Then you should set up your !setleaderboard command like so:

!addcom !setleaderboard -a=!commands edit !leaderboard Current Leaderboard: $(query) $(urlfetch https://pastebin.com/raw/XXXXXXXX)

Don't forget to replace XXXXXXXX with your paste ID.

And in your unlisted never-expiring paste, simply write: $(query)

In general if we want an alias of !editcom to edit a command to have a variable $(varname) in its response, we can output it by eval to stop Nightbot from parsing it.

$(eval `$`+`(varname)`)

If we want !setleaderboard to have $(query) in its response we can do

!addcom !setleaderboard -a=!editcom !leaderboard Current Leaderboard: $(eval `$`+`(query)`)

Thank you so much, I dont know why this work around never occured to me but i did figure out how to make it work with this!

This format didnt quite end up working the way i needed it to but thank you nonetheless! This particular format should help in different commands if i try to modify them! It also helped me remember that !editcom works as the full alias command rather than the -a=!commands edit

Oh right, I forgot we could do it this way... I'm so used to needing more than just a $(query), in which case a Pastebin makes more sense. Thank you for the reminder.

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

Ask on Discord