Want a quick and easy command to let your users generate a silly dad joke? Easy. Here’s how to set up a command in Nightbot that will allow your users to type !dadjoke and your bot will create a dad joke.
Use the iCanHasDadJoke API
The easiest way to do this kind of command in a bot like Nightbot is to use an external API that provides the random result. If you can find or make an API endpoint that returns a simple text result, you can easily use it in most chatbots. With Nightbot we do so using the urlfetch variable, which we’ll get into into later.
To generate a random dad joke, we’re using the icanhazdadjoke.com API, specifically with the /nightbot parameter at the end which forces it to return text only.
Ultimately, the URL that you should copy and paste is: https://icanhazdadjoke.com/nightbot
Setting Up the Command
I’ll assume you already have Nightbot set up and have added it to your channel. If you have not, go see this guide about setting up Nightbot, and then come back here when you’re done.
Next, go the the dashboard, click commands on the left-hand navigation, and then click custom to load the custom commands page. Here you’ll see any other custom commands you may have made already.
Then click the add command button.
In the dialogue that appears, enter !dadjoke as the command. In the Message field, type or copy/paste the following string (you can triple-click to copy easily):
$(urlfetch https://icanhazdadjoke.com/nightbot)
Keep Userlevel set to Everyone unless you have a particular reason to lock this down to VIPs or Moderators or something. You can also set a cooldown here, but the default of 5 seconds is fine unless your chat really abuses it for some reason. Don’t worry about the Alias field, that’s kind of advanced usage and honestly, I don’t find it particularly useful. Go ahead and click Submit and you’re done!
Now when your viewers type !dadjoke in chat, the bot will make a dad joke by calling that API endpoint and sending the result to chat. I hope you don’t have too many groaners.
Enjoy, and feel free to send this along to anyone else who might like to create a dad joke command with Nightbot.