Using urlfetch to get joke from website

I’m trying to use a timer to pull up a random joke off the Web. In this instance I’m using the url http://www.mightyjokes.com/random
So the joke is already randomly selected by that website, by my understanding, nightbot now should be reading that page and posting it to my chat in Twitch.
I tried this in timers, message, left other two fields empty and it just throws the link down.
I tried using $(urlfetch http://www.mightyjokes.com/random) command in timers, message, left other two fields empty and it just throws the link down but showing the command prompt.
I tried using $(urlfetch same url ) command in alias had to put something in message so typed letters url the results of this failed.
Anyone able to help? Am I doing this wrong? Is it impossible what I am asking of nightbot?

The site would need to return in plaintext the joke (not a formatted HTML page like it does). You would need to find something that does that for this to work.

Thanks for getting back so quickly.
So I need to find something that would convert the ‘joke text’ to plaintext, I’ll work on that.
Which commands were the correct ones to be using out of the 3 I tried?

You would just put the command you want to call it with (e.g. !joke) in the Command box, then $(urlfetch url) in the Message box to return the joke.

You can read more on using $(urlfetch) and other variables on the docs.

Thank you for your response,
I’ve read the docs I sort of understand the logic of timers and commands.
I wanted a random joke every so often. So it has to be in timers section of nightbot, this I understand. Timers only have 3 fields, name, message and alias, this is clear to me.
So I am, as far as I have discovered, Naming it joke, message is random joke for you, alias is $(urlfetch url)
I may have overlooked the plaintext part, but I now understand the bot can only retrieve and place data that is of plaintext format less than 400 characters.
So if my timer input above is incorrect that is now what I need to know in order to get a control timer so to speak so I can try different websites and converters that are available to me.

Or do I need to add this joke part to commands first, then do the set up in timers and then I should have better luck assuming I find a source with correct parameters for nightbot to use.

The Alias field is for calling a separate command so in most cases you should just leave it blank, you can put both your message and variables like $(urlfetch) in the message box.

With timers the only box you really need to worry about is the message, you should set it up to look something like this:

1 Like

Perfect, well thanks to the both of you I now fully understand this and it works! Thank you very much for your time and effort!!! I appreciate it greatly!!!

1 Like

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