Struggling to use eval & urlfetch together?

$(urlfetch (my api url)/nightbot/multiline?raw=true&msgs=$(eval const names = '$(querystring)'.split(' '); const channels = names.map(n => $(twitch ${n} "{{url}} - [{{game}}]")).join(' |'); const initText = encodeURIComponent('Please check out the following channels:') + ' |'; const msgs = [initText, channels].join(''); msgs))

Can someone help me find out whats wrong here? Its posting everything in this block above ^ instead of the api response, im intending on.

Hey @itsjusttriz!

I’d suggest using an alias command, I believe Nightbot calls the $(urlfetch) before resolving the $(eval), so something like this should solve your problem:

!addcom !commandName -a=_commandName $(eval const names = decodeURIComponent('$(querystring)').split(' '); const channels = names.map(n => $(twitch ${n} "{{url}} - [{{game}}]")).join(' |'); const initText = encodeURIComponent('Please check out the following channels:') + ' |'; const msgs = [initText, channels].join(''); msgs)

!addcom _commandName $(urlfetch https://yourApi.url/nightbot/multiline?raw=true&msgs=$(querystring))

I’m getting a

missing ) after argument list

!multiso

$(eval const names = decodeURIComponent('$(querystring)').split(' '); const channels = names.map(n => $(twitch ${n} "{{url}} - [{{game}}]")).join(' |'); const initText = encodeURIComponent('Please check out the following channels:') + ' |'; const msgs = [initText, channels].join(''); msgs)

!_multiso_api

$(urlfetch https://api.itsjusttriz.com/nightbot/multiline?raw=true&msgs=$(querystring))

Of course!
I barely checked your code, but there’s an important mistake here:
names.map(n => $(twitch ${n} "{{url}} - [{{game}}]"))
Can you see it?

Here’s the fix, I highlighted the important parts:
names.map(n => `$(twitch ${n} "{{url}} - [{{game}}]")`)


But even that isn’t enough, and that’s because the $(twitch) variable is resolved before the .map() is called, I wonder if the following would fix it completely:

!addcom !multiso -a=_commandName $(eval const names = decodeURIComponent('$(querystring)').split(' '); const channels = names.map(n => `(twitch ${n} "{{url}} - [{{game}}]")`); const twitch = channels.map(c => '$' + c).join(' |'); const initText = encodeURIComponent('Please check out the following channels:') + ' |'; const msgs = `${initText} ${channels}`; msgs)

And in the alias command, try with $(querystring), but if it doesn’t work, try with $(query).

Now this:

I need it to resolve the mapped $(twitch) before calling $(urlfetch)

Damn, so close! I’m not sure I have a solution to offer anymore…

I made a similar command before, but I don’t have the game listed, only the URL, which can be done simply by concatenating twitch.tv/ and the username, so I don’t rely on the $(twitch) variable.
I wonder if I faced the same problem as you and forgot, since it’s been years at this point.

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