How to make command work only when Live

I saw this command in another thread but when I use it when offline it still shows.

$(eval u=$(twitch $(channel) "{{uptimeLength}}");if(u.toLowerCase()===channel is not live){Just offline} else{$(lastfm LASTFMNAMEACC "{{title}} by {{artist}}")})

Hey @questions!

The key is to check whether the streamer is live, and if not, send a string that’s made of a space, the bot won’t throw an error, and the chat will automatically discard the message as empty:

$(eval '$(twitch $(channel) "{{status}}")' === 'live' ? 'YOUR_MESSAGE_WHEN_LIVE' : ' ';)
1 Like

The following commands can be tried,Replace the following text with “MESSAGE_LIVE” and “MESSAGE_OFFLIVE”.

$(eval s = $(twitch $(touser) "{{status}}"); s == ‘live’ ? $(twitch $(touser) "{{displayName}} is now ${s} MESSAGE_LIVE") : s == ‘offline’ ?$(twitch $(touser) "{{displayName}} is now ${s} MESSAGE_OFFLIVE") : ``;)

1 Like

Thanks for the help, I am trying this way, it looks like it is working in offline chat.

What do you mean by that? Because that command doesn’t send a response when I’m not live, so if it does for you, then you must have made a mistake in editing the code I provided.

Oh sorry, I meant that as working as intended (not showing in offline chat). But I messed it up for how it shows when online because now it shows an error:

$(eval ‘$(twitch $(channel) “{{status}}”)’ === ‘live’ ? ‘$(lastfm LASTFMACC “{{title}} by {{artist}}”)’ : ’ ':wink:

Oh, okay, I see.
Well, I dusted off my LastFM account just to test, and I don’t get any error with the following code:

$(eval '$(twitch $(channel) "{{status}}")' === 'live' ? '$(lastfm LASTFM_USERNAME "{{title}} by {{artist}}")' : ' ';)

What I think happened is that the quotes in your code were updated from " and ' to “” and ‘’, which usually happens when the code is copied in a word processor app, such as Microsoft Word for example, the issue is that JavaScript doesn’t recognize the latter quotes. To avoid it, copy/paste the code we provide on the forum directly in your Twitch chat, or in Nightbot’s dashboard, and edit the code there, or use a note app, they don’t usually format the quotes, such as Notepad for example.

1 Like

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